wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner class doubt" Watch "Inner class doubt" New topic
Author

Inner class doubt

Neha Monga
Ranch Hand

Joined: Mar 13, 2007
Posts: 34
Hello Ranchers!



ouput --> Hello
Default

Pls explain why the output is NOT -->
Default
Default

Appreciate your help!

Thanks
Neha Monga
anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447
Hi

neha

In inner = o.new In();

When the jvm executes this statement, the default constructor of the Out will be executed because in extends Out.There you are setting the id="Default",And in the inner class if you simply say id ,means this.id.Because In extends Out the id is inherited to the subclass because it is not declared as private.

This is a specaial syntax to get refernce to the top level class.
System.out.println(Out.this.id);//refers to

Out o = new Out("Hello");//line 1
In this the default constructor won't run.

Thanks
Anil Kumar

[ May 31, 2007: Message edited by: anil kumar ]
[ May 31, 2007: Message edited by: anil kumar ]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Neha,

Adding to what Anil said:

If you get how many times the no-arg constructor of class Out is called,
you can make yourself doubt clear.



cmbhatt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class doubt
 
Similar Threads
Inner Class - Initialization Sequence
Nested class
what is super?
Explanation needed for a question
Understanding Inner Class Output