The only time a subclass of an abstract class is not forced to implement all abstract methods of its superclass, is if the subclass is also an abstract class.
Abstract Methods
An abstract class can have abstract methods. You declare a method abstract by adding the abstract keyword in front of the method declaration. Here is how that looks:
An abstract method has no implementation. It just has a method signature.
If a class has an abstract method, the whole class must be declared abstract. Not all methods have to be abstract, even if the class is abstract. An abstract class can have a mixture of abstract and non-abstract methods.
The Purpose of Abstract Classes
The purpose of abstract classes is to function as base classes which can be extended by subclasses to create a full implementation. For instance, imagine that a certain process requires 3 steps:
The step before the action.
The action.
The step after the action.
If the steps before and after the action are always the same, the 3-step process could be implemented in an abstract superclass like this:
public abstract class MyAbstractProcess {
public void process() {
stepBefore();
action();
stepAfter();
}
public void stepBefore() {
//implementation directly in abstract superclass
}
public abstract void action(); // implemented by subclasses
public void stepAfter() {
//implementation directly in abstract superclass
}
}
Notice how the action() method is abstract. Subclasses of MyAbstractProcess can now extend MyAbstractProcess and just override the action() method.
When the process() method of the subclass is called, the full process is executed, including the action() method of the subclass.
Of course, the MyAbstractProcess did not have to be an abstract class to function as a base class. Nor did the action() method have to be abstract either. You could have just used an ordinary class. However, by making the method to implement abstract, and thus the class too, you signal clearly to the programmer, that this class should not be used as it is, but be used as a base class for a subclass, and that the abstract method should be implemented in the subclass.
