Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Abstract Classes and Concrete Classes

In Java an abstract class  is one that does not provide implementations for all its methods. A class must be declared abstract if any of the methods in that class are abstract. For example, the GraphicalObject class defined in Program gif is declared abstract because its draw method is abstract.

An abstract class is meant to be used as the base class from which other classes are derived. The derived class is expected to provide implementations for the methods that are not implemented in the base class. A derived class that implements all the missing functionality is called a concrete class .

In Java it is not possible to instantiate an abstract class. For example, the following declaration is illegal:

GraphicalObject g = new GraphicalObject (new Point (0,0)); // Wrong.
If we were allowed to declare g in this way, then we could attempt to invoke the non-existent method g.draw().


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.