Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which can method2 can access without reference?

 
james gong
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read the code which can the method2 access without reference ?
//*****************code*************//
class A
{
public int x;
public int y;
class B{
protected void method1(){};
class C
{
protected void method2(){}
}
}
}
//***********code_end**************//
key:the x,y,method1 are the method2 can access without reference;
 
r balasubramanian
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gong,
Since an inner class can access only the members of enclosing the class, in this case method2 can access only method1 of class B.
If you have any other answer, please mail me at pillaiyar72@hotmail.com
R.Balasubramanian
Originally posted by james gong:
read the code which can the method2 access without reference ?
//*****************code*************//
class A
{
public int x;
public int y;
class B{
protected void method1(){};
class C
{
protected void method2(){}
}
}
}
//***********code_end**************//
key:the x,y,method1 are the method2 can access without reference;

 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James
The inner class C can access any of the variables in C or A. All it needs to do is refer to the variable directly. If one of the inner classes hides one of the variables from an enclosig class then you use the syntax OuterClass.this.variable to access it. the code below should illustrate that for you:

If you have any questions let me know

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic