This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Inner class" Watch "Inner class" New topic
Author

Inner class

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
class outer
{
protected class inner
{
public inner()
{ System.out.println("in inner");
}
}
private inner p1;
outer()
{System.out.println("in constructor of outer class");
p1=new inner();//1
}
public static void main(String a[])
{ new outer(); }
}
AT line 1 i.e even before an object of outer class is created
inner class object is created.How is it working??? since
innerclass can be created after outer class object is created.
Thanks!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12268
    
    1
Actually, the outer object has been constructed at line 1. The compiler supplies a call to the Object constructor as an unseen first line, so by line 1 the memory for the object has been reserved and initialized to 0.
Bill

Java Resources at www.wbrogden.com
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks!Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class
 
Similar Threads
naming : package, inner classes
inner class
class types
Does static variables of static inner class will be loaded as soon as outer class name is countered.
Question on inner classes