Consider the following UML diagram:
(Notice that Ball
is in italics, indicating that it is abstract.)
For example, the cell marked with red would represent the following assignment:
// Variable type: Football / Object type: Tossable Football ball = new Tossable();This cell should is marked — because it is impossible to instantiate an object of type
Tossable
.
Variable Type | ||||||
Tossable | Ball | Rock | Baseball | Football | ||
Object Type | Tossable | — | ||||
Ball | ||||||
Rock | ||||||
Baseball | ||||||
Football |
1. Ball ball = new Football("Spalding"); 2. Ball ball = new Football("Spalding"); Baseball baseball = (Baseball)ball; 3. Object obj = new Baseball("Spalding"); 4. Object obj = new Baseball("Spalding"); Tossable tossable = obj; 5. Tossable tossable = new Baseball("Spalding"); Object obj = tossable; 6. Tossable tossable = new Baseball("Spalding"); tossable.getBrandName();
toss
or bounce
methods.