0

Can we used this keyword in method overloading in java.

7th Mar 2020, 9:55 AM
Pooja Jagnade
Pooja Jagnade - avatar
2 Respuestas
0
Please tag the language - Java, not '@'
7th Mar 2020, 10:43 AM
Ipang
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); } }
7th Mar 2020, 5:39 PM
Jayakrishna 🇮🇳