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.
class
Test
{
int
a;
int
b;
// Parameterized constructor
Test(
int
a,
int
b)
{
this
.a = a;
this
.b = b;
}
void
display()
{
//Displaying value of variables a and b
System.out.println(
"a = "
+ a +
" b = "
+ b);
}
public
static
void
main(String[] args)
{
Test object =
new
Test(
10
,
20
);
object.display();
}
}