It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Classes..! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Classes..!" Watch "Inner Classes..!" New topic

Inner Classes..!

Nilesh Raje
Ranch Hand

Joined: Aug 02, 2005
Posts: 153
Hello Friends,

This question is from!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
Don Retag

Joined: Aug 15, 2005
Posts: 7
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.
Santana Iyer
Ranch Hand

Joined: Jun 13, 2005
Posts: 335
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..!
It's not a secret anymore!