Java Reference
In-Depth Information
΢ Exercise R9.3. Suppose the class Sandwich implements the Edible
interface, and you are given the variable definitions
Sandwich sub = new Sandwich();
Rectangle cerealBox = new Rectangle(5, 10,
20, 30);
Edible e = null;
Which of the following assignment statements are legal?
a. e = sub ;
b. sub = e ;
c. sub = (Sandwich) e ;
d. sub = (Sandwich) cerealBox ;
e. e = cerealBox ;
f. e = (Edible) cerealBox ;
g. e = (Rectangle) cerealBox ;
h. e = (Rectangle) null ;
΢΢ Exercise R9.4. How does a cast such as (BankAccount) x differ from
a cast of number values such as (int) x ?
΢΢ Exercise R9.5. The classes Rectangle2D.Double ,
Ellipse2D.Double , and Line2D.Double implement the Shape
interface. The Graphics2D class depends on the Shape interface but
not on the rectangle, ellipse, and line classes. Draw a UML diagram
denoting these facts.
΢΢ Exercise R9.6. Suppose r contains a reference to a new
Rectangle(5, 10, 20, 30) . Which of the following assignments
is legal? (Look inside the API documentation to check which interfaces the
Rectangle class implements.)
a. Rectangle a = r ;
Search WWH ::




Custom Search