This question already has an answer here:
I have some questions around abstract classes and their use. I know the basics about them; for example, that they can't be instantiated, they can have concrete and abstract methods, ... But I guess what I wanna know is, what purpose do they serve in life (in software engineering)?
What is the purpose of abstract classes in Java? Why and when should one use an Abstract class? If you can use a normal class and then inherit it, why would you inherit an abstract class? How would using abstract classes make our life easier? would it provide better maintainability? more flexibility? ...
btw, I've already looked at some similar questions and answers, including Understanding the purpose of Abstract Classes in Java, but they don't answer my question. I'm more looking for answers that shed light on the philosophy behind the introduction of abstract classes in the first place in Java.
Thanks
An
abstract
class can be used as a type of template for other classes, and most commonly used forinheritance
.The best example is from the book head first java:
then you can extend child class such as:
dog
,cat
,fish
.