wood burning stoves 2.0*
The moose likes Java in General and the fly likes Without using THIS operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Without using THIS operator" Watch "Without using THIS operator" New topic
Author

Without using THIS operator

Praveen Ramachandran
Greenhorn

Joined: Jul 18, 2006
Posts: 16
public class A {
public A(){
System.out.println(this + ": Called me");
}
}

public class B extends A {
public B(){

}
}


public class C extends A {
public C() {

}
}


public class D {

/**
* @param args
*/
public static void main(String[] args) {
A a1 = new A();
B b1 = new B();
C c1 = new C();
}

}


This program would simply print the object which called it..
Can we do this w/o using 'this' operator.Please let me know
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

The following code does exactly the same as your code but without using the "this" keyword:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
jQuery in Action, 2nd edition
 
subject: Without using THIS operator