Static variables are one per entire class, not one per instance.
Both g.y
and h.y
(and G.y
) refer to the same variable, so the last assignment wins, and the value is 2.
It is confusing to access a static
variable via an instance of the class, but Java allows it.