• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

problem from sun sample

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given the following question, I am definate about option e as correct, but for non-static inner classes should'nt option c also hold correct considering (new outer.new inner) must be mentioned in the enclosing class.
Thanx
5. Which statement is true about a non-static inner class?
A.It must implement an interface.
B.It is accessible from any other class.
C.It can only be instantiated in the enclosing class.
D.It must be final if it is declared in a method scope.
E.It can access private instance variables in the enclosing object.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think only E is correct in this case.
A)It must implement an interface. - FALSE. There is no such condition.
B)It is accessible from any other class. - FALSE.Not always.If we have a private non-static inner class then it is NOT accessible even if we do have an istance of the outer class available with us.
C)It can only be instantiated in the enclosing class - FALSE.It can be instantiated in any class if a reference to the enclosing class is available.It is true if we have a private non-static inner class , but that is not mentioned here.
D)It must be final if it is declared in a method scope. - FALSE.No such condition.
E)It can access private instance variables in the enclosing object. -TRUE.A non-static inner class can access private member variables of outer class.

------------------
Come on in !! Drinks are on the house in the Big Moose Saloon !!
 
It was the best of times. It was the worst of times. It was a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic