A superclass method is called instead of the subclass method

后端 未结 3 547
庸人自扰
庸人自扰 2020-12-11 19:25

Let\'s take a look at this code:

public class ParentClass {
    public void foo(Object o) {
        System.out.println(\"Parent\");
    }
}

public class Sub         


        
3条回答
  •  春和景丽
    2020-12-11 20:10

    Strings are objects in java, as said its not overridden but as you pass a string it will run the first available method that can the the argument, in this case it is the super-class's method.

提交回复
热议问题