A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
this week in the
Programmer Certification (SCJP/OCPJP)
Joined: Aug 02, 2005
Aug 25, 2005 22:37:00
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..!
Thanks and Regards,<br />Nilesh<br />SCJP 1.4, SCWCD 1.4
Joined: Aug 15, 2005
Aug 25, 2005 23:01:00
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.
Joined: Jun 13, 2005
Aug 26, 2005 04:54:00
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.
I agree. Here's the link:
subject: Inner Classes..!
accessible variable in inner class
any difference between inner class and nested class?
JSecure mock exam doubts
Mock exam Q- Which variables can an inner class access?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014