Intro of JAVA
Learn Java
Java this keyword is used to reference the object of current class.It can only be used within constructors or instance methods.this keyword can also be pass as argument in method or constructor call.
Note:1.It differentiate instance variable from local variable,if both have same values within constructor or method.Mainly used to invoke method or constructor.
2.It allow to write constructor under another constructor.
this keyword program
class Abd{
int id;
Abd (int id){
this.id=id;}
void display()
{System.out.println(id);
}
public static void main(String args[])
{
Abd a1=new Abd(10);
a1.display();
}
};
Output: