aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class... how and why ? 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... how and why ?" Watch "Inner class... how and why ?" New topic
Author

Inner class... how and why ?

Pascal Got
Greenhorn

Joined: Mar 05, 2002
Posts: 23
Hi,
I have some questions, not on syntax but more on 'how and why' ?
- Why would one want to instanciate an inner class before instanciating the outer class ?

- When instanciating an outer class, is the inner being instanciated as well (automatically) If 'yes' why does the language enbales instanciation of an inner independently of it outer class ?
Please give me some example (short)...
Thx
Pascal
zarina mohammad
Ranch Hand

Joined: Jun 26, 2002
Posts: 104
check out the campfire story about Inner class. http://www.javaranch.com/campfire.jsp
Easier way to understand about Inner classes.
-zarina
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
You can't instantiate an inner class prior to instantiating the enclosing class. All inner classes must have an enclosing instance in order to exist. The inverse is not true. You do not need to instantiate an inner class to instantiate an outer class. By that, I mean that, if an outer class has a reference to an inner class, that reference can remain null after the outer class is instantiated.
You can, however, create an instance of a top-level nested class (which is like an inner class, but it is static, so it's not truly an inner class) without an instance of the enclosing class.
I hope that helps,
Corey


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class... how and why ?