• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inner class mult choice

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic