wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessing Outer Class variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Accessing Outer Class variable" Watch "Accessing Outer Class variable" New topic
Author

Accessing Outer Class variable

Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76


I thought this will compile and output 78 & 20 but i am getting a compile error saying variable y can't be accessed.
Correct me if i am wrong here, inner class should be able to access any outer class variable..including a private???

TIA
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
In a bit of a hurry so don't have time to check, but at first sight try Outer.this.y
out is an instance of Outer.Inner; y is a variable of Outer..


Regards,
Ken
Looluo Zhu
Greenhorn

Joined: Nov 26, 2003
Posts: 8
You can access y in the body of Inner, not by a reference of Inner.


SCJP 1.4
Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
The only way I was able to get at the value of Outer.y was by adding a method to the Inner class as indicated below:



I then changed the final line to be:

Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
Sorry, the previous post should read as:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing Outer Class variable
 
Similar Threads
head first java - mixed messages
doubt in InnerClass
Question from vodoo exam
Inner Class
inner classes