aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner classes" Watch "Inner classes" New topic
Author

Inner classes

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
class MyOuter2
{
private String x = "Outer2";
public static void main(String args[])
{
MyOuter2.MyInner i = new MyOuter2().new MyInner();
i.seeOuter();
}
void doStuff()
{
class MyInner
{
public void seeOuter()
{
System.out.println("Outer x is " + x);
} // close inner class method
} // close inner class definition
} // close outer class method doStuff()
} // close outer class


THE ABOVE PROGRAM WITH RESPECTIVE TO INNER CLASSES IS GIVING COMPILE TIME ERRORS.

Can anybody provide the explanation for the above?

Thanks,
venkat
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Hi,
This is a K&B example,read the following statement stated there:



So,you need to do this instead,as shown in book:

Hope that helps!!!


SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner classes
 
Similar Threads
where final variable reside ?
Doubts regarding Method Local Inner Class
Final variable access from class inside function
Code for Method-Local Inner Classes not compiling
needs explanation