This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Usage of this with inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Usage of this with inner classes" Watch "Usage of this with inner classes" New topic

Usage of this with inner classes

Sekhar Choudary
Ranch Hand

Joined: May 03, 2008
Posts: 57
source code is as follows

class MyOuter{
class MyInner{
public void m1(){
System.out.println("This class refernce:"+this);
System.out.println("Outer class refernce:"+MyOuter.this);
//#line 1 Insert here



public void m2(){ System.out.println("Outer classes method"); }

public class InnerThisEx{

public static void main(String[] args){

MyOuter.MyInner ob=new MyOuter().new MyInner();

Now my question is ,can we insert any of the following statements at line#1 for successful compilaton.
If so, let me the reason.

Thank you.
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 122
how about compiling & checking it ???

i think the 1st one will work but the 2nd one won't

SCJP 6 83%
Sandeep Bhandari
Ranch Hand

Joined: Apr 16, 2004
Posts: 201
and use code tags to make the code readable

SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
Bhanurekha Chintagunta

Joined: Jul 28, 2008
Posts: 4
MyOuter.this is an Object refrence to MyInner class, not method that takes
void as param. so 2) does not compile.

I agree. Here's the link:
subject: Usage of this with inner classes
jQuery in Action, 3rd edition