0
Can we used this keyword in method overloading in java.
2 Respuestas
0
Please tag the language - Java, not '@'
0
'this' keyword refers to current class object.
No problem if it overloading or not, doesnot effect...
Example, run this and see..
class One
{
int x,y;
One()
{
this.x=0;
this.y=0;
}
public void set(int x)
{
this.x=x;
}
public void set(int x,int y) //overloading
{
this.x=x;
this.y=y;
}
}
public class Program
{
public static void main(String[] args) {
One n=new One();
System.out.println(n.x+" " +n.y);
n.set(8);
System.out.println(n.x+" "+n.y);
n.set(8,9);
System.out.println(n.x+" "+n.y);
}
}