File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local inner class acces .. help !

 
sarim raza
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because varuable v is local to the method and it is perfectly legal to access it from inside the method.
 
sachin patel
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here aMethod2 is a method of Inner class and not outer class so it is legal to refrence v in that method.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After all, the PURPOSE of passing in int v is to use it in the method, otherwise why bother?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic