Can an Abstract class have a constructor?

 Posted by vishalneeraj-24503 on 9/6/2014 | Category: OOPS Interview questions | Views: 2366 | Points: 40
Answer:

Yes,an Abstract Class can have a constructor.In general,a class constructor is used to initialize fields or variables.An abstract class constructor is used to initialize fields of the abstract class.We would provide a constructor for an abstract class if we want to initialize certain fields of the abstract class before the instantiation of a child-class takes place. An abstract class constructor can also be used to execute code that is relevant for every child class.This prevents duplicate code.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response