• 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 Classes..!

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,

This question is from 4tests.com..!Please Justify the answers for this question.


Which variables can an inner class access from the class which encapsulates it?

1)All static variables
2)All final variables
3)All instance variables
4)Only final instance variables
5)Only final static variables

The Answers given are (1)(2)(3)

Thanks in advance..!
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
options 4) and 5) are mutually exclusive with options 1) 2) 3). If either one is true, the other is false. For class-level inner-classes, not method local inner classes, the class has full access to final and instance variables.
 
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inner class in above question means regular inner class defined inside class.

It can access all variable of enclosing class as it exists only with an enclosing instance.

For inner class defined inside method can not access local variables defined inside method however it can access final local variable. It can access encolsing instance members.

Hope this helps.
 
reply
    Bookmark Topic Watch Topic
  • New Topic