When to use abstract classes in java?
If same kind of derived classes has some thing in common, and if you don't know some of the specific functionalities, then we can use abstract classes. Eg: Rectangle, Circle, Line everything is a shape. And we know that every shape will have color, x, y co-ordinates. But we don't know the specific functionalities like area, because area formula will change for specific shape.
Abstract classes will be heavily used in framework layer classes, where you know how to handle generic events coming to all the applications, but you don't know what to do in startup() and shutdown() functionalities. (Because these are specific to applications)
If you are providing some functionalities for some un related classes , then don't use abstract classes.
all are true.
You can go for abstract classes in all the above mentioned scenarios.
Back To Top