This Keyword in JAVA
To refer a object is called reference variable.
“this” keyword is also a reference variable that refer to the current object.
Class Test { int i; void SetValue(int i) { i=i; } void show() { System.out.println(i); } } class Demo { public static void main(String[] args) { Test t = new Test(); t.SetValue(10); t.show(); } }
Instance variables and local variables name are same put that are local value that time value of I is zero
to resolve this program this.i referees to current instance of object that means I value is = 10
Class Test { int i; void SetValue(int i) { this.i=i; } void show() { System.out.println(i); } } class Demo { public static void main(String[] args) { Test t = new Test(); t.SetValue(10); t.show(); } }