Wednesday 9 November 2016

Using ‘this’ Keyword



o   this keyword can be used inside any method to refer to current object.
o   this is always a reference to the object on which the method was invoked.
Ex:Myclass(int a,int b) {
                   this.a=a;
                   this.b=b;
                 }
In situations when a local variable has the same name as an instance variable, the local variable hides the instance variable. this keyword is used to access the instance variable that have the same name as the local variable.

No comments:
Write comments