what is the use of constructor inside abstract class

Instance of Abstract class cant be created but still there are few things that needs to be taken care:

1. Whenever you inherit a class to a parent class, at least one constructor of the parent class should be called by child class, other wise Exception will be thrown.Reason is given below, why it is so.

2. Basic use of constructor is to make sure that the class should be initialized properly or should be in proper state before you get your hands dirty on its instance/object. So same thing happens when you do inheritance, before the child instance is created, we need to make sure parent as well as child should be in proper state andsince Abstract classes can provide partial implementation so that should also be in proper state before you create an instance of child class.

No comments:

Post a Comment