why we are using this. in java
/*this keyword in Java is a reference variable that refers to the current object
of a method or a constructor. The main purpose of using this keyword in Java is
to remove the confusion between class attributes and parameters that have same names.
For Example; if we have */
class Account{
int a;
int b;
public void setData(int a ,int b){
a = a;
b = b;
}
public void showData(){
System.out.println("Value of A ="+a);
System.out.println("Value of B ="+b);
}
public static void main(String args[]){
Account obj = new Account();
obj.setData(2,3);
obj.showData();
}
}
/*it's Output will be a=0 & b=0;
but if we replace this.a=a & this.b=b;
So now the answer will be a=2 ,a=3.*/