Page 585 - Introduction to Programming with Java: A Problem Solving Approach
P. 585
• You can safely cast a more generic reference into a more specific type only if you know the actual ob- ject referred to will be as specific as or more specific than the cast.
• You can implement polymorphism in an array of heterogeneous objects by declaring the array elements to be instances of a common inheritance ancestor. To satisfy the compiler, you can write a dummy method in that ancestor class and override it in all classes instantiated in the array. Or you can de- clare the method in an abstract ancestor class and then define overriding methods in all descendant classes instantiated in the array. Or you can declare the method in an interface and implement that in- terface in all classes instantiated in the array.
• A class can extend one inherited superclass and/or implement any number of interfaces.
• An interface provides simple access to common constants.
• The protected access modifier provides direct access to members of classes in the same package or
in the inheritance subtree whose root is the class in which the protected member is declared.
• With the aid of explicit trigonometric calculations, you can use Java API classes to draw what appear to
be three-dimensional objects.
Review Questions
§13.2 The Object Class and Automatic Type Promotion
1. If you want a class you define to inherit methods from the Object class, you must append the suffix,
extends Object, to your class’s heading. (T / F)
Apago PDF Enhancer
§13.3 The equals Method
2. When used to compare reference variables, the == operator works the same as the Object class’s equals
method. (T / F)
3. What does the equals method defined in the String class compare?
§13.4 The toString Method
4. What is returned by the Object class’s toString method?
5. What’s wrong with replacing the println statement in Figure 13.2’s main method with these two
statements?
String description = car.toString();
System.out.println(description);
6. The return type of an overriding method must be the same as the return type of the overridden method. (T / F)
§13.5 Polymorphism and Dynamic Binding
7. In Java, polymorphic method calls are bound to method definitions at compile time (not runtime). (T / F)
§13.6 Assignments Between Objects in a Class Hierarchy
8. Assume one reference variable’s class is descended from another reference variable’s class. To be able to
assign one reference variable to the other one (without using a cast operator), the left-side variable’s class must be a(n) of the right-side reference variable’s class.
§13.7 Polymorphism with Arrays
9. A given array may contain elements of varying type. (T / F)
Review Questions 551