Outer outer = new Outer();
an Object
of Outer
class is created on heap and reference variable points to it.
If I understand it right when I write
Outer.Inner inner=outer.new Inner();
an object of Inner
class is created on heap and inner
points to it. In heap we have two separate objects which contains their own instance variables.
But if I write
Outer.Inner inner=new Outer().new Inner();
still two Object
would be created on heap one for Outer
and other for Inner
. But with reference the inner
only Inner
Object's
members are accessible . Who is referring to the outer Object
on heap? If it is not referred by any reference then it should be eligible for garbage collection which would then impact the usage of inner
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…