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
posted
0
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
posted
0
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
posted
0
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