File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class" Watch "inner class" New topic

inner class

Sunita Vontel
Ranch Hand

Joined: Aug 28, 2000
Posts: 72
Please see the following program

The result is inner,outer. I thought it will be inner, inner.Why does O.this.s print outer??

[This message has been edited by Sunita Vontel (edited August 31, 2000).]
Karthik Subramanian

Joined: Aug 23, 2000
Posts: 27

Hello Sunita,
I hope you got how ,
System.out.println(s+ ","); is printing "inner,"
In the statement , System.out.println(O.this.s);
O.this refers to the inner
class object ,simply because the object that is invoking the method is of inner class type.
It is something like Inner()
Hence it prints the string variable of th inner class. I hope it is clear.

Joined: Aug 28, 2000
Posts: 28
a similar example is given in "jamie jaworski" book.
here Outer.this.s refers to the s variable of the Outer class,
as Outer.this is an instance of Outer class that u are referring to here.
hope u got it, maha
Sunita Vontel
Ranch Hand

Joined: Aug 28, 2000
Posts: 72
Thanks mahaadd
Hey karthik u said it is inner , inner but it prints inner,outer.
I agree. Here's the link:
subject: inner class
It's not a secret anymore!