Can an abstract class have a constructor?

前端 未结 22 2185
甜味超标
甜味超标 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:15

    An abstract class can have a constructor BUT you can not create an object of abstract class so how do you use that constructor?

    Thing is when you inherit that abstract class in your subclass you can pass values to its(abstract's) constructor through super(value) method in your subclass and no you don't inherit a constructor.

    so using super you can pass values in a constructor of the abstract class and as far as I remember it has to be the first statement in your method or constructor.

提交回复
热议问题