Java Abstract Classes
Abstract Classes
An abstract class is a class that contains abstract functionality to be implemented by subclasses. In other words, an abstract class presents only an abstract form and is used to defer the actual implementation to subclasses.
An abstract method is a method defined inside an abstract class that has only a declaration part and no implementation part. This method forces subclasses that inherit the abstract class to implement it by redefining, or overriding, it. If a subclass that inherits an abstract class does not redefine the abstract method, that subclass must also become an abstract class. Also, any class that has even one abstract method must be an abstract class.
An object instance cannot be created from an abstract class alone. In other words, an object cannot be declared using the new keyword. This is because the abstract class contains abstract methods, which are incomplete methods. Therefore, an object can be created only as an object of a subclass after the subclass inherits the abstract class and redefines the abstract methods.
Defining Abstract Classes and Methods
Abstract classes and abstract methods use the abstract keyword. Since an abstract method has no implementation part, the method declaration ends immediately with a semicolon (;).
abstract class ClassName {
// Member variables, same as a general class
// Methods, same as a general class
abstract returnType abstractMethodName(parameterType parameter);
}