Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will members be compiled into subclass's .class file?

In java, will inherited members(static or instance, method or field) be compiled into subclass's .class file?

Or just keep a link to the super class's relavent member?

like image 847
xingbin Avatar asked Feb 22 '26 18:02

xingbin


1 Answers

As far as class files are concerned, inherited members are not copied into subclasses. Here is relevant documentation from Oracle (emphasis added):

  • 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.

like image 178
Sergey Kalinichenko Avatar answered Feb 25 '26 08:02

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!