Private members in Java inheritance

后端 未结 5 654
执笔经年
执笔经年 2020-12-01 06:43

I was told that for a Java subclass it can inherit all members of its superclass. So does this mean even private members? I know it can inherit protected members.

C

5条回答
  •  情深已故
    2020-12-01 07:40

    IMO by no way is it a matter of definition. In class-based Inheritance implies propagation of behavior to descendants. As such private members DO get inherited , and I will not go into the details how this happens.

    Actually I find the "not inherited" answer to be dangerous for new developers and they do not comprehend right away that the private members are there hidden under the skin of your class and they (can) have severe impact on its behavior, size of the objects etc.

    It is common that "development comes before understanding" in computer science, however lets avoid building (or destroying) our conceptualization of OOP assuming the wrong "definition" adopted by some technician writing the manual of a well known class based OO platform.

    Sorry for stating something in such an old post, but the issue is always valid.

提交回复
热议问题