File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner class" Watch "Inner class" New topic

Inner class

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
class outer
protected class inner
public inner()
{ System.out.println("in inner");
private inner p1;
{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.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
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.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I agree. Here's the link:
subject: Inner class
It's not a secret anymore!