Category:
Java
this keyword provides reference to the current object and it’s mostly used to make sure that object variables are used, not the local variables having same name.
classTest
{
inta;
intb;
// Parameterized constructor
Test(inta, intb)
{
this.a = a;
this.b = b;
}
voiddisplay()
{
//Displaying value of variables a and b
System.out.println("a = "+ a + " b = "+ b);
}
publicstaticvoidmain(String[] args)
{
Test object = newTest(10, 20);
object.display();
}
}