Java Reference
In-Depth Information
Answers to Review Questions
1.
Poly means many, and morph means form. Polymorphism refers to the ability of an
object to take on many forms.
2.
A class declared abstract cannot be instantiated.
3.
The class must also be declared abstract, and any child classes either must override
the abstract method or declare themselves abstract as well.
4.
The Cat class does not override the abstract nurse() method in Mammal. The Cat class
contains a nurse() method, but it has a different parameter list than nurse() in Mam-
mal. This is an example of method overloading, not method overriding. The Cat class
can either be declared abstract or define a nurse() method that is public, void, and has
no parameters, similar to the one in Mammal.
5.
Yes. A Mammal reference can refer to a Whale object because a Whale is a Mammal.
6.
Invoking breathe() and nurse() on a Whale object has the same result, whether the
reference used is of type Whale (like w) or of type Mammal (like m). The output is:
Whale is breathing
Mammal is breathing
Whale is nursing
Whale is breathing
Mammal is breathing
Whale is nursing
7.
True. m is a reference of type Mammal, but it is an instance of a Whale.
8.
True. w refers to a Whale object. A Whale object is a Mammal object, so w is an
instance of Mammal.
9.
False. m refers to a Whale, and a Whale object is not a Cat object.
Search WWH ::




Custom Search