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.
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
Here is its definition from the Oracle Java documentation,
public abstract class Number extends Object implements Serializable
implements keywords for now, we will discuss them in a future section.
Other classes such as the
Long inherit from the
Number class and provide concrete implementations.
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
- An abstract method cannot be marked with the
- An abstract class can have static fields and methods. The static members can be accessed in the same way using the