Due to the JVM specification the class
file is build this way:
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
The super_class
field consists:
`For a class, the value of the super_class item either must be zero or must be a valid index into the constant_pool table. If the value of the super_class item is nonzero, the constant_pool entry at that index must be a CONSTANT_Class_info (§4.4.1) structure representing the direct superclass of the class defined by this class file. Neither the direct superclass nor any of its superclasses may have the ACC_FINAL flag set in the access_flags item of its ClassFile structure.
If the value of the super_class item is zero, then this class file must represent the class Object, the only class or interface without a direct superclass.
For an interface, the value of the super_class item must always be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Class_info structure representing the class Object.`
More interesting is the fields[]
part:
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.
So the compiled class doesn't contain inherited fields. On the other hand when an object is created the private
super fields are in memory. Why? Let's imagine the example:
classs A {
int a;
A(int a) {
this.a = a;
}
void methodA() {
System.out.println("A is: " + a);
}
}
classs B extends A {
int b;
B(int b) {
super(10);
this.b = b;
}
void methodB() {
super.methodA();
System.out.println("B is: " + b);
}
}
The output should be: A is: 10 \n B is ...
.