my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes local inner class acces .. help ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "local inner class acces .. help !" Watch "local inner class acces .. help !" New topic
Author

local inner class acces .. help !

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
Given the code below
public class OuterClass{
private int x = 20;
final int y = 10;
public void aMethod1(final int z){
int w = 5;

class InnerClass{

private void aMethod2(int v){
//Some Valid code
}
}
}
}

Select the variable that may be referenced by the
InnerClass mehtod aMethod2()

A.x
B.y
C.z
D.w
E.v
//I LIKE A, B AND C BUT ANSWER INCLUDES E AS WELL, WHY ?
Rajiv Ranjan
Ranch Hand

Joined: Sep 28, 2000
Posts: 61
Because varuable v is local to the method and it is perfectly legal to access it from inside the method.
sachin patel
Ranch Hand

Joined: Nov 28, 2000
Posts: 75
here aMethod2 is a method of Inner class and not outer class so it is legal to refrence v in that method.


Sachin,<P>****************************************************<BR>Learn from others mistakes. Life is too short to make all yourself.<BR>****************************************************
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
After all, the PURPOSE of passing in int v is to use it in the method, otherwise why bother?


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: local inner class acces .. help !
 
Similar Threads
Declaration of inner class
Why interface does not allow to reference a variable in super class using super keywo
When can a classes be declared private?
Inner Class
Inner class basics. (Marcus Green's mock exam 2)