It's not a secret anymore!
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Without using THIS operator" Watch "Without using THIS operator" New topic

Without using THIS operator

Praveen Ramachandran

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: 14991

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 8 API documentation
I agree. Here's the link:
subject: Without using THIS operator
It's not a secret anymore!