gpt4 book ai didi

java - OOP 和私有(private)字段的继承

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:10:00 26 4
gpt4 key购买 nike

<分区>

在 C# 中,规范说:

Instance constructors, destructors, and static constructors are not inherited, but all other members are, regardless of their declared accessibility (§3.5). However, depending on their declared accessibility, inherited members might not be accessible in a derived class.

因此私有(private)字段被继承到派生类中,但它们不可访问。

但是 Java 规范说:

Only members of a class that are declared protected or public are inherited by subclasses declared in a package other than the one in which the class is declared.

因此私有(private)字段不会继承到派生类中。

OOP 理论的解释是什么?正确的是 C# 还是 Java 设计者?

在这方面有点困惑。

附言我没有 C++ 经验? C++ 设计师对此怎么说?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com