class Demo1{
<code>void m1(int a) {
System.out.println(a);
}
</code>
<code>void m1(int a) {
System.out.println(a);
}
</code>
void m1(int a) {
System.out.println(a);
}
}
class Demo2 extends Demo1{
<code>void m1(int a) {
System.out.println(a+a);
}
void m1(int a, int b) {
System.out.println(a+b);
}
</code>
<code>void m1(int a) {
System.out.println(a+a);
}
void m1(int a, int b) {
System.out.println(a+b);
}
</code>
void m1(int a) {
System.out.println(a+a);
}
void m1(int a, int b) {
System.out.println(a+b);
}
}
public class OveridingVsOverloading {
<code>public static void main(String[] args) {
// TODO Auto-generated method stub
Demo1 obj= new Demo1();
//obj.m1(5);
Demo2 obj1= new Demo2();
obj1.m1(1,2);
obj1.m1(10);
obj1.m1(100);
}
</code>
<code>public static void main(String[] args) {
// TODO Auto-generated method stub
Demo1 obj= new Demo1();
//obj.m1(5);
Demo2 obj1= new Demo2();
obj1.m1(1,2);
obj1.m1(10);
obj1.m1(100);
}
</code>
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo1 obj= new Demo1();
//obj.m1(5);
Demo2 obj1= new Demo2();
obj1.m1(1,2);
obj1.m1(10);
obj1.m1(100);
}
}
I’m expecting the output as
3
10
200
I’m getting
3
20
200
How will object from child class call demo1 method from parent, if both the arguments are same. i.e int a
New contributor
Disco Yapper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.