aspose 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class" Watch "inner class" New topic
Author

inner class

kevin goon
Ranch Hand

Joined: Jun 12, 2001
Posts: 62
package foo;
public class Outer
public static class Inner
Which statement true?
a. An instance of the Inner class can be constructed
statement with "new Outer.Inner()"
b. An instance of the Inner class can't be constructed
outside of package foo
c. An instance of the Inner class can only be constructed
from within the Outer class
d. From within the package bar, an instance of the Inner
class can be constructed statement with "new Inner()"
ans : a) but Why is b incorrect? Isnt b true since tha package statement is declared??
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Kevin,
You're correct. You can create a <code>Outer.Inner</code> class from outside the package. The following two examples compile and run without error.

Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
kevin goon
Ranch Hand

Joined: Jun 12, 2001
Posts: 62
thank you for your reply
I tried to compile your coding but for some reason it didnt work. I throws NoClassDefFoundException
Let me just make sure if I understood right.
So the answer choice B would be incorrect from my original question right?? since you CAN create instance outside package b importing the file.
How about if you remove the import statement from your subclass? Then it wouldnt work?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: inner class
 
Similar Threads
inner classes
Inner Classes
a question about instantiating an inner class
Nested classes
Exam questions on inner classes -help!