3:50 pm - Wednesday February 19, 7502

Keyword this in java with Example Program

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

keyword : this

‘this’ is used for pointing the current class instance. It can be used with variables or methods. Look into the following example:

class Test{
private int i=10;
public void m(){
System.out.println(this.i);
}
}

In the above code this is used for the current instance. Since this is
instance of a class it cannot be used inside a static method.

when the local variable and member variable are same then we use this keyword as ,

class A

{

int w;

public void setValue(int w)

{

this.w=w;

}

}

(Or)

this() can be used to invoke a constructor of the same class .

BACK

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply