File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

needs explanation

 
Venkat Ramsimha
Ranch Hand
Posts: 127
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class MyOuter2 {
private String x = "Outer2";
void doStuff() {
class MyInner {
public void seeOuter() {
System.out.println("Outer x is " + x);
} // close inner class method
} // close inner class definition
MyInner mi = new MyInner(); // This line must come
// after the class
mi.seeOuter();
} // close outer class method doStuff()
} // close outer class

can anybody provide with the explantion as how the output is generated?

thanks
venkat
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you create an instance of MyOuter2 and call the doStuff() method...
  • Within doStuff(), a new instance of MyInner is created using the local class definition.
  • The method seeOuter() is called on that instance.
  • The method seeOuter() prints a line, accessing MyOuter's private variable x in the process.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic