File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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

Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99
Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
Actually, the answers have to be C and D.

A and B are both wrong for the same reason: InnerClass doesn't exist statically, so there's no way to instantiate it independently of OuterClass. If you stick lines A and B inside a non-static method of OuterClass, then they would work.

E is wrong because it uses this, which is not available in a static context.

C and D both create instances of OuterClass before trying to create an InnerClass.
[ August 24, 2005: Message edited by: Ryan Kade ]
Bhaskar Dabbigodla
Greenhorn

Joined: Aug 02, 2002
Posts: 10
Answer C is OK but I am surprised how D is correct. Is it not required to represent the InnerClass with OuterClass.InnerClass i = o.new InnerClass() notation.


Thanks and Regards,<br />Bhaskar Dabbigodla<br />SCJP1.4 (98%)
Aakash Parashar
Ranch Hand

Joined: Jul 25, 2005
Posts: 122

Bhaskar,

Constructor of Innerclass is invoked from main which is a static method. So, without creating instance of Outerclass that constructior cannot be accessed from main method.


Your's Aakash
SCJP 1.4 96%, SCBCD 1.3 94%, http://java-application-programming.blogspot.in
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
This one confused me a bit so I tried to find as many ways as I could think of instantiating an inner class and tried them in both a static and non-static context. These were my results:



Hope that is helpful.
Josh


Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Class