Page 586 - Introduction to Programming with Java: A Problem Solving Approach
P. 586
552 Chapter 13 Inheritance and Polymorphism
§13.8 abstract Methods and Classes
10. What are the syntax features of an abstract method?
11. Any class that contains an abstract method must be declared to be an abstract class. (T / F) 12. You cannot instantiate an abstract class. (T / F)
§13.9 Interfaces
13. You can use an interface to provide direct access to a common set of constants from many different classes.
(T/F)
14. You can declare reference variables to have an interface type and use them just like you would use reference
variables declared to be the type of a class in an inheritance hierarchy. (T / F)
§13.10 The protected Access Modifier
15. Describe the access provided by the protected modifier.
16. It’s illegal to use private for any method that overrides an abstract method. (T/F)
Exercises
1. [after §13.3] Write a sameColorAs method for the Car class in Figure 13.1. It should return true if the compared cars’ colors are the same, regardless of their other attributes.
2. [after §13.4] Write the output produced by the program in Figure 13.2. Apago PDF Enhancer
3. [after §13.4] What does the following program output? For each dog’s output, describe how the output is generated (be specific).
public class Animal
{
public static void main(String[] args)
{
}
Animal sparky = new Dog();
Animal lassie = new Animal();
System.out.println(
"sparky = " + sparky + "\tlassie = " + lassie);
// end main
} // end Animal
class Dog extends Animal
{
public String toString()
{
}
return "bark, bark";
} // end class Dog
4 [after §13.4] What happens if you add an object of a class that does not define a toString method to an ArrayList, and then you try to print the ArrayList? (Assume the object’s class is a programmer- defined class that does not have an extends phrase in its heading.)
5. [after §13.5] Why is dynamic binding often called late binding?
6. [after §13.6] Given: Animal superclass, Dog subclass.