Java Reference
In-Depth Information
Self-Test Exercises (continued)
15.
The abstract class Employee given in Display 8.7 has a constructor (in fact, it
has more than one, although only one is shown in Display 8.7). But using a
constructor to create an instance of an abstract class, as in the following, is illegal:
Employee joe = new Employee(); //Illegal
So why bother to have any constructors in an abstract class? Aren't they useless?
Chapter Summary
Late binding (also called dynamic binding ) means that the decision of which version
of a method is appropriate is decided at run time. Java uses late binding.
Polymorphism means using the process of late binding to allow different objects to
use different method actions for the same method name. Polymorphism is essentially
another word for late binding .
You can assign an object of a derived class to a variable of its base class (or any ances-
tor class), but you cannot do the reverse.
If you add the modifier final to the definition of a method, it indicates that the
method may not be redefined in a derived class. If you add the modifier final to
the definition of a class, it indicates that the class may not be used as a base class to
derive other classes.
An abstract method serves as a placeholder for a method that will be fully defined in
a descendent class.
An abstract class is a class with one or more abstract methods.
An abstract class is designed to be used as a base class to derive other classes. You can-
not create an object of an abstract class type (unless it is an object of some concrete
descendent class).
An abstract class is a type. You can have variables whose type is an abstract class and
you can have parameters whose type is an abstract type.
Answers to Self-Test Exercises
1. In essence, there is no difference between the two terms. There is only a slight
difference in their usage. Late binding refers to the mechanism used to decide
which method definition to use when a method is invoked, and polymorphism
refers to the fact that the same method name can have different meanings because
of late binding.
2. There would be problems well before you wrote the program in Display 8.3 . Since
final means you cannot change the definition of the method bill in a derived
 
Search WWH ::




Custom Search