java - 成员会被编译成子类的.class 文件吗?

标签 java inheritance subclass superclass .class-file

在java中,继承的成员(静态或实例,方法或字段)会被编译到子类的.class文件中吗?

或者只保留父类(super class)相关成员的链接?

最佳答案

就类文件而言,继承的成员不会复制到子类中。这是 relevant documentation from Oracle (强调):

  • fields[] Each value in the fields table must be a field_info (§4.5) structure giving a complete description of a field in this class or interface. The fields table includes only those fields that are declared by this class or interface. It does not include items representing fields that are inherited from superclasses or superinterfaces.

  • methods[] Each value in the methods table must be a method_info (§4.6) structure giving a complete description of a method in this class or interface. [...] The method_info structures represent all methods declared by this class or interface type, including instance methods, class methods, instance initialization methods (§2.9), and any class or interface initialization method (§2.9). The methods table does not include items representing methods that are inherited from superclasses or superinterfaces.

关于java - 成员会被编译成子类的.class 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49503870/

相关文章:

c++ - 无法在 C++ 中访问派生类的函数

java - 如何在 Eclipse 中查找给定类的哪些子类实现了特定接口(interface)?

java - clojure 是否可以读取和处理编译器生成的类(.class 文件)?

java - Guice 初学者 - 如何绑定(bind)具体类 - 单例?

java - 在jsp中将变量添加到mysql查询的末尾?

c# - C# 中的私有(private)继承?

c# - 属性继承与反射

python - 子类化 float 以强制 python 中的定点打印精度

java - 类继承的最佳设置

java - 您推荐哪种 Swing 布局?