This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inner class  RSS feed

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