Java Reference
In-Depth Information
11.24
✓
✓
Indicate true or false for the following statements:
Check
Point
You can always successfully cast an instance of a subclass to a superclass.
■
You can always successfully cast an instance of a superclass to a subclass.
■
11.25
For the
GeometricObject
and
Circle
classes in Listings 11.1 and 11.2, answer the
following questions:
a. Assume are
circle
and
object
created as follows:
Circle circle =
new
Circle(
1
);
GeometricObject object =
new
GeometricObject();
Are the following Boolean expressions true or false?
(circle
instanceof
GeometricObject)
(object
instanceof
GeometricObject)
(circle
instanceof
Circle)
(object
instanceof
Circle)
b. Can the following statements be compiled?
Circle circle =
new
Circle(
5
);
GeometricObject object = circle;
c. Can the following statements be compiled?
GeometricObject object =
new
GeometricObject();
Circle circle = (Circle)object;
11.26
Suppose that
Fruit
,
Apple
,
Orange
,
GoldenDelicious
, and
McIntosh
are
defined in the following inheritance hierarchy:
Fruit
Apple
Orange
GoldenDelicious
McIntosh
Assume that the following code is given:
Fruit fruit =
new
GoldenDelicious();
Orange orange =
new
Orange();
Answer the following questions:
a. Is
fruit instanceof Fruit
?
b. Is
fruit instanceof Orange
?
c. Is
fruit instanceof Apple
?
d. Is
fruit instanceof GoldenDelicious
?
e. Is
fruit instanceof McIntosh
?
f.
Is
orange instanceof Orange
?
Search WWH ::
Custom Search