This keyword in Java
Hello friends today we discuss few points related to This keyword in Java."this" keyword is used at two place.
1. At method level
2. At constructor level
this keyword used always for represent reference of current object
Using this with a Field
For example, the Area class was written like thispublic class Area
{
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b)
{
x = a;
y = b;
}
}
Using this with a Constructor
public class Area
{
public int x = 0;
public int y = 0;
//constructor
public Area(int x, int y)
{
this.x = x;
this.y = y;
}
}
Here you can get few information related to this keyword; for detail you can visit our website: This keyword in Java
No comments:
Post a Comment