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 mult choice 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 mult choice" Watch "Inner class mult choice" New topic
Author

Inner class mult choice

Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172
Which statement is true about an inner class?
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D. It can only be instantiated in the enclosing class
E. It can access any final variables in any enclosing scope.
Their answer: E
My answer: C and E
C- because you need:
OuterClass.InnerClass x = new OuterClass().new InnerClass()
Whos right?
Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
Originally posted by Paul Salerno:
My answer: C and E
C- because you need:
OuterClass.InnerClass x = new OuterClass().new InnerClass()


You could do OuterClass.InnerClass x = new OuterClass().new InnerClass() from some OTHER class, though, and doesn't have to be done inside the "enclosing class"(the class that has the inner class in it).
swapna sivaraju
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
Its only E
as the statement C says---it "can only" be instantiated in the enclosing class
but this is not true as the non static inner classes can be instantiated in any class but
it's instance can be created in context of an
instance of the enclosing class..ie..
Outer.Inner in=Outer.new().new Inner();

swapna


SCPJ2
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by Paul Salerno:
Which statement is true about an inner class?
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D. It can only be instantiated in the enclosing class
E. It can access any final variables in any enclosing scope.
Their answer: E
My answer: C and E
C- because you need:
OuterClass.InnerClass x = new OuterClass().new InnerClass()
Whos right?

The option C says
C. It is only accessible in the enclosing class
They can be accessed outside of the enclosing class too. Yes you need an Outer Class instance to INSTANTIATE an Inner Class instance(not true for static inner classes), but that instance can invoke methods of Inner class from Other classes too.
So C is not right!!!
Amish
Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172
Thank you all
 
wood burning stoves
 
subject: Inner class mult choice
 
Similar Threads
Interview questions
Jaworski mock - statements on non-static inner class
problem from sun sample
Innerclasses