Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13044
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Thanks!Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic