This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
in your code
there are three Test classes
first is with package scope
another that created in the public class is inner class for P688_Question08_Ask
and another is method local inner class in the main method
now on line 13, the class Test is instantiated but that class is not the method local inner class (Remember that method local inner class cannot be instantiated before creating it)
so the call
checks for the class that is regular inner class or another simple class
in this case we have both
but nearest scope is for the regular inner class in public class P688_Question08_Ask
so line 13 invocation prints "middle"
line 19 instantiation and invocation prints inner because the METHOD LOCAL INNER CLASS is instantiated now as we are instantiating it AFTER class declaration
to verify this
just comment out the regular inner class i.e. line 22 to 26
line 13 invocation will cause outer class Test to get instantiated as inner class is not available now
and the output will change to
hope this helps
SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Joined: Oct 24, 2010
Thanks Prasad. Good explanation. One final question is, How class Test at Line 22 takes higher precedence(nearest execution spot) over class Test at at Line 1..What is that concept ?