What is the purpose of abstract class?
Printable View
What is the purpose of abstract class?
It is not an instantiable class. It provides the concrete implementation for some/all the methods. So that they can reuse the concrete functionality by inheriting the abstract class.For more information about Purpose of abstract class go to the following link below java developer course
abstract class is a class where it has implemented and non-implemented methods.
This is kinda similar to interface but in this case the inherited class can reuse the abstract classe's concrete methods as well as implement the non-implemented methods.
Thus reducing the amount of work by typing redundant methods over and over again.
Thats one of its uses.
Inheritance.
The main purpose of Abstract class is polymorphism
The abstract class should represent a concept and provide all interfaces necessary to represent that concept. Each derived class will have its own implementation of the concept. However client will never know / or not required to know about implementation of actual implementation. what all he cares about the abstract concept.
There is an alternative to abstract class i.e. Interface. Interface should be used when you want to define purely interface, no concrete implementation of any method. Interface acts as Facade so basically you can use it to define different level of interfaces to different client using different Interfaces with same implementation.
e.g. A class can cook Classic pizza, Butter Pizza and special Pizzza.
Pizza shop has distributed some coupon for advertisement, and the coupon get you classic pizza free.
I can create a interface which exposes only cooking classic pizza interface, securing my other pizzas against free coupon policy.