Some questions about abstract class with private, public and protected constructors

前端 未结 5 1323
北海茫月
北海茫月 2021-02-09 21:30

My first question: What is the difference between an protected and a public constructor in an abstract class?

My second questions: Does it make sense, if the abstract cl

5条回答
  •  余生分开走
    2021-02-09 22:22

    Question #1: Not much. You can't call the constructor of an abstract class (instantiate it) directly anyway. You could only call one from a subclass, which means you'd definitely have access to protected members as well as public members at that point.

    Question #2: No, not much sense. A private constructor on an abstract class could only be called by "constructor chaining" from a non-private constructor in the same class.

提交回复
热议问题