Can an abstract class have a constructor?

前端 未结 22 2503
甜味超标
甜味超标 2020-11-22 05:25

Can an abstract class have a constructor?

If so, how can it be used and for what purposes?

22条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 06:16

    In order to achieve constructor chaining, the abstract class will have a constructor. The compiler keeps Super() statement inside the subclass constructor, which will call the superclass constructor. If there were no constructors for abstract classes then java rules are violated and we can't achieve constructor chaining.

提交回复
热议问题