Hi all, Can someone explain why I get "STP as output from this program even though the println statements show that my understanding that "default" is the last value assigned is correct, in the program below:
Line 4 will call function on Line 2, and the Line 3 will be excuted as follows OuterTest . this . id whcih can be looked as OuterTest-->CurrentlyExceutingThread-->its id So which makes it as OuterTest.Outer.id which is STP
To get the default as output in the last line, you have to change the Line 1 to static String id ;
In Line 1 we are creating an object of OuterTest with one argument. Thus id for that object will be set as �STP�.
Now in Line2 we use the above created object to create an object of InnerTest class. So for InnerTest�s object, id will hold the value �Default�.
Now in doSomething method we are calling OuterTest.this.id which means we want the value of id for the Parent class of the current object. Ie id of the object through which the object of InnerTest was created. Thus this means that we are trying to fetch the value of id for the object called �outer�. Thus it prints �STP�.
If we want to print �Default� than just modify doSomthing() method as follows
Now the last line of o/p will be �Default�. This is b�cos value of id is set as �Default� by the constructor of InnerTest which calls its parents� no argument constructor,
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
a bit of art, as a gift, that will fit in a stocking