Using inherited overloaded methods

后端 未结 11 1764
北荒
北荒 2020-12-15 05:50

I have two classes:

public class ClassA {
    public void method(Number n) {
        System.out.println(\"ClassA: \" + n + \" \" + n.getClass());
    }
}
         


        
11条回答
  •  爱一瞬间的悲伤
    2020-12-15 06:14

    Your issue stems from the fact that (as quoted from the official Java tutorials on Inheritance):

    In a subclass, you can overload the methods inherited from the superclass. Such overloaded methods neither hide nor override the superclass methods—they are new methods, unique to the subclass.`

    Refer to the official Java tutorials for more details: http://docs.oracle.com/javase/tutorial/java/IandI/override.html

提交回复
热议问题