java - A superclass method is called instead of the subclass method -
let's take @ code: public class parentclass { public void foo(object o) { system.out.println("parent"); } } public class subclass extends parentclass { public void foo(string s) { system.out.println("child"); } public static void main(string args[]) { parentclass p = new subclass(); p.foo("hello"); } } i expected print out "child", result "parent". why java call super class instead, , do make call method in subclass? subclass#foo() not override parentclass#foo() because doesn't have same formal parameters. 1 takes object , other takes string . therefore polymorphism @ runtime not applied , not cause subclass method execute. java language specification : an instance method m c declared in or inherited class c, overrides c method m a declared in class a, iff of following true: a superclass of c. c not inherit m a . the signature of