This keyword in Java
This Keyword in Java is generally used in java for refer current class object. Here we also discuss about why use this keyword in java.
Some other uses of this keyword are;
- It is used to refer to current object.
- It is 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.
class ThisDemo
{
Double width, weight, dept;
Box (double w, double h, double d)
{
this.width = w;
this.height = h;
this.depth = d;
}
}
Here this keyword used for refer current class object.
this keyword is used to return current Object
public Box area()
{
return this;
}
No comments :
Post a Comment