File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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%)
 
wood burning stoves
 
subject: Inner classes
 
Similar Threads
Code for Method-Local Inner Classes not compiling
where final variable reside ?
Doubts regarding Method Local Inner Class
needs explanation
Final variable access from class inside function