This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Usage of this with inner classes  RSS feed

 
Sekhar Choudary
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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);
this.m2();
//#line 1 Insert here

m2();

}//m1
}//myinner

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

public class InnerThisEx{

public static void main(String[] args){

MyOuter.MyInner ob=new MyOuter().new MyInner();
ob.m1();
}//main
}//class


Now my question is ,can we insert any of the following statements at line#1 for successful compilaton.
If so, let me the reason.
1.MyOuter.this.m2();
2.MyOuter.this(m2());

Thank you.
 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about compiling & checking it ???

i think the 1st one will work but the 2nd one won't
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and use code tags to make the code readable
 
Bhanurekha Chintagunta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyOuter.this is an Object refrence to MyInner class, not method that takes
void as param. so 2) does not compile.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!