abstract Classes and Methods

index
INTERMEDIATE

An abstract method is one that is declared but not defined; that is, it has no body. Any methods declared in an interface are automatically abstract, and need not be explicitly marked as such. Abstract methods declared in a class must be so marked, for example,

abstract double computeSomething(double x, double y);

Any class that contains abstract methods must itself be declared abstract, for example,

public abstract class DataGatherer { ... }

However, a class may be declared abstract without actually containing abstract methods. Abstract classes may not be instantiated (you cannot create objects of that class), but can be subclassed, and the subclass can provide the missing method definitions.

Abstract classes are used when some methods can be defined, but the definition of other methods must be left to subclasses.