aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes needs explanation 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 "needs explanation" Watch "needs explanation" New topic
Author

needs explanation

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
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

Joined: Aug 31, 2004
Posts: 11343

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.


  • "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    sscce.org
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: needs explanation