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