Private Members in a Superclass
A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods for accessing its private fields, these can also be used by the subclass.
which is why this works (printing "1")
So are private variables actually always inherited, but it's just that you can't access them if they're private?
Say I have some huge private object like an image file declared in the superclass
are all my ClassD instances going to be huge as well?
BTW it doesn't make any difference in which class the main method is located.
Members [of a class] are either declared in the type, or inherited because they are accessible members of a superclass or superinterface which are neither private nor hidden nor overridden (§8.4.8).
Luigi Plinge wrote:...are private variables actually always inherited, but it's just that you can't access them if they're private? ...
In fact, some authors phrase it that way. For example, The Java Tutorial says...
A subclass inherits all the member variables and methods from its superclass. However, the subclass might not have access to an inherited member variable or method. For example, a subclass cannot access a private member inherited from its superclass. One might say, then, that the item was not inherited at all. But the item is inherited.
The first edition of Mugal & Rasmussen's, A Programmer's Guide to Java Certification said that private members "are still inherited, but they are not accessable in the subclasses." Then they changed their minds (with an interesting qualification) for the second edition: "Private members are not accessible from any other class. This also applies to subclasses... Since they are not accessible by simple name in a subclass, they are also not inherited by the subclass."
However, the "definitive" Java Language Specification - 8.2 states...
Members of a class that are declared private are not inherited by subclasses of that class.
So I would say, conceptually yes. Private members of a superclass are "part of" a subclass instance, and are reachable (as you've demonstrated). However, I would avoid the word "inherited," because the JLS is clear about this.