Yes, Java will allocate space for two object references - one for Foo.field and one for Bar.field . In short, this could be a way to render an instance of Foo in memory:
[header] (references Foo.class, Bar.class, Object.class, among other details) [Section for Bar]: Field, declared type String, referencing a `java.lang.String` with value "Bar" [Section for Foo]: Field, declared type String, referencing a `java.lang.String` with value "Foo"
The offsets of these fields are known to the JVM and are used when reading / writing them.
Please note that this does not mean that Foo contains a Bar , but rather Foo is a Bar and more.
source share