In the InnerTest instance there is a id field inherited, however Outer.this.id is also accesible. The latter is a field of the containing class, it will be initialized by a constructor of its class: new OuterTest("STP"). The former would be intialized by InnerTest constructor, either directly (id="something" or indirectly by calling super(); Try System.out.println(OuterTest.this.id +"\t"+ id); and you will see STP Default STP Default
super() calls the no-args (default) constructor of the superclass, in this case, OuterTest(). Inside this OuterTest() constructor, the variable id of InnerTest is assigned to "Default", because 'this' is referring to the current object. So OuterTest's id is still "STP". Hope you understood. Ana
Welcome to the Ranch Ana. ____________________________________________________ Cathy, within a constructor or instance method id is equivalent to this.id . this is the hidden argument to instance methods representing the object on which the method was called: "aCar.go();" within go() this refers to aCar. this in a constructor is the object being initialized, that is the object created by new.
SCJP2. Please Indent your code using UBB Code
Don't MAKE me come back there with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss