Uses of this Keyword in Java
Uses of this keyword in Java
The main uses of this keyword in java is; this keyword is used to refer to current object. It always a reference to the object on which method was invoked. It can be used to invoke current class constructor. It can be passed as an argument to another method.
Example of this keyword in java
class BoxExample
{
Double width, weight, dept;
Box (double w, double h, double d)
{
this.width = w;
this.height = h;
this.depth = d;
}
}
this keyword is used to return current Object
public Salary getSalary()
{
return this;
}
No comments:
Post a Comment