I do not understand this Java behavior. I have two classes:
class C1 {
public void m1(double num) {
System.out.println(\"Inside C1.m1(): \" + num
Since C1.m1(double num)
is a public method, it inherited C2. So your C2 also has a method, m1(double num)
, and that's why it is called. From main()
you actually called C2.m1(double num)
.
Note: Now at class C2
you have two overloaded methods -
m1(int num)
and m1(double num)
. And C2.m1(int num)
is a different method from C2.m1(double num)
.