Abstract classes are usually meant to share pieces of implementation and to be extended:

Abstract Methods

Abstract methods are methods declared without an implementation (no body and semicolon at the end).

An important thing to remember about abstract methods is that if a class has one or more abstract methods then the class itself must also be declared abstract. The reason is that an abstract method has no implementation and so it wouldn’t be possible to instantiate an object of such a class (partially implemented).

Abstract Classes

The things that you need to know about abstract classes for the exam are:

  • They cannot be instantiated, but can be extended
  • They may or may not have abstract methods
  • If a subclass of an abstract class doesn’t provide implementations for all the abstract methods, it must also be declared abstract
  • They may have static fields and static methods
  • Unlike interfaces:
    • They can contain implemented methods
    • They can contain fields that aren’t constants (static and final)

Abstract classes implementing interfaces are allowed not to implement all of the interface methods, but the subclasses must implement the remaining methods:

Leave a Reply