Calling overloaded inherited methods using super class reference

后端 未结 10 1286
既然无缘
既然无缘 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:41

    By looking at your code, you are not taking advantage of inheriting to get the answer you want. You have to change this line

    C1 c = new C2();
    

    to

    C2 c = new C2();
    

提交回复
热议问题