Java Programming/Keywords/this
From Wikibooks, open books for an open world
this is a Java keyword. It contains the current object reference.
Syntax:
this.method(); orthis.variable;
Example #1:
|
public class MyClass
{ //... private String _memberVar; //... public void setMemberVar( String value ) { this._memberVar= value; } } |
Example #2:
|
public class MyClass
{ MyClass(int a, int b) { System.out.println("int a: " + a); System.out.println("int b: " + b); } MyClass(int a) { this(a, 0); } //... public static void main(String[] args) { new MyClass(1, 2); new MyClass(5); } } |
This page may need to be