Abstract Classes

There are two kinds of classes in Java: concrete classes and abstract classes. A concrete class is a class that you can use to make an instance. An abstract class, on the other hand, cannot be instantiated. Syntactically, an abstract class is any class that contains at least one abstract method. Consider a class Airplane:

public class Airplane
    {
      int numberofWings;
      String engineType;
       public boolean startEngine()
            {
              // logic to start an engine goes here
            }
     }

This class specifies a generic airplane. Although it is syntactically correct, there are a couple of potential problems with this class definition that give rise to the need for abstract classes. First, there's no such thing as a generic airplane. There are Boeing 747s, there ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.