Abstract Classes

An abstract class is a class that is declared with the abstract keyword. It provides a partial implementation that other classes can build on. Abstract class cannot be instantiated but they can be subclassed.

An abstract class may or may not include abstract methods. A class with an abstract method should be declared abstract.

An example of an abstract class is the Number class from the java.lang package.

Here is its definition from the Oracle Java documentation,

public abstract class Number
extends Object
implements Serializable

Ignore the extends and implements keywords for now, we will discuss them in a future section.

Other classes such as the Byte, Double, Float, Integer, Short and Long inherit from the Number class and provide concrete implementations.

Abstract Methods

Abstract methods are methods defined with the abstract keyword and do no provide any implementation. The methods do not have bodies, missing curly braces.

Here is the definition of the intValue abstract method in the Number class :

 public abstract int intValue();

static with Abstract Members

  1. An abstract method cannot be marked with the static keyword.
  2. An abstract class can have static fields and methods. The static members can be accessed in the same way using the className.field orclassName.method()

results matching ""

    No results matching ""