tulshiram kamble wrote:is we can say "this" is used for memory reusability
No. I don't even know what you mean by "memory reusability".
When describing the execution of Java code, there is a notion of a "current object." The purpose of the this keyword is to provide a way to refer to that "current object" in the code.
No there is no memory reuse as the variable is not free nor any allocation takes place.
The "this" keyword just works like a reference to the current object as you do not have an explicit reference.
The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.
For example, the Point class was written like this
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b) {
x = a;
y = b;
}
}
but it could have been written like this:
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
Each argument to the constructor shadows one of the object's fields — inside the constructor x is a local copy of the constructor's first argument. To refer to the Point field x, the constructor must use this.x.
as we know "this" hold address of current object suppose if we assign value to current object and we call methods with parameter as a same variable name
it will be changes to change d current object value
memory re-usability means as we know current object have memory address ,when we call methods along with parameter have same variable name,
"this" will point or refer to current object so this current object address will be reusable again. i think your getting my point this statement.