wood burning stoves 2.0*
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
Author

Inner class

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
Hi,
this is a question from a mock exam.
If
inner - refers to a static inner class
outer - refers to the enclosing class
which of the following statements are true?
1.Outer outerObj = new Outer() ;
Outer.Inner InnerObj1 = outerObj.new Inner() ;
2. Outer.Inner InnerObj2 = new Outer.Inner() ;
3.Outer.Inner InnerObj3 = new Outer().new Inner() ;
given ans:1,2
My answer is only 2 because according to me there is no difference between 1 and 2.
Any comments would be appreciated.

-Sanjana
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Option 1 shouldn't even compile because the syntax is plain wrong.

An instance of a static inner class cannot be created using an instance of its enclosing class. Top level nested classes maintain no special relationship between their enclosing classes, it's slightly more than namespacing resolution. By convention, the full qualified name of the class is used to instantiate a static inner class outside of its outer class.
sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
Yes Vad Fogel. I agree with you. That's why i wanted to reconfirm. Thanks for your reply.

-Sanjana
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class