aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes which can method2 can access without reference? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "which can method2 can access without reference?" Watch "which can method2 can access without reference?" New topic
Author

which can method2 can access without reference?

james gong
Ranch Hand

Joined: May 29, 2001
Posts: 48
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

Joined: Jul 25, 2001
Posts: 11
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

Joined: May 10, 2001
Posts: 3244
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


Dave
 
jQuery in Action, 2nd edition
 
subject: which can method2 can access without reference?