The are many uses of abstract clasees, the main purpose of abstract classes is to function as base classes which can be extended by subclasses to create a full implementation.
For example,
You may have three steps to be implemented in your program,
- Few steps before the action
- Some action to be performed
- Few steps after the action
So in this case you can define an abstract class with the three methods like this:
public abstract MyAbstractProcess {
public void stepBefore() {
//implementation directly in abstract superclass
}
public abstract void action(); // implemented by subclasses
public void stepAfter() {
//implementation directly in abstract superclass
}
}
Also, the above example of abstract class Animal is also a very good example.