Calling overloaded inherited methods using super class reference

后端 未结 10 1297
既然无缘
既然无缘 2020-12-29 07:38

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         


        
10条回答
  •  天命终不由人
    2020-12-29 08:18

    Java does method dispatch on static types, and your variable c is of type C1, so m1(int) is not visible, and your 10 is cast to double.

提交回复
热议问题