|
|
|
|
However, a class with one or more abstract methods must itself be declared abstract:
(The Java compiler will remind you if you forget!) An abstract method promises that all non-abstract subclasses of this class will implement that abstract method. Abstract methods act as placeholders for methods to be implemented in the subclasses. A class contains abstract methods if any of the following is true:
Only abstract classes may contain abstract methods. If a class contains abstract methods, but is not declared abstract, then a compile-time error occurs. The Methods of Abstract ClassesAbstract classes do not have to contain only abstract methods. They may contain a mixture of abstract and concrete methods -- and in fact, usually do. It is a good idea to push as much functionality as possible (as appropriate to that class) into the more abstract classes -- it allows you to reuse code more easily. You may declare a class to be abstract, even if it does not contain any abstract methods. This prevents the class from being instantiated. |
|
This page was last modified on 02 October, 2007 |