SE450: Overriding: Overloading [12/35] |
To override a method, the argument types must be the same in super and subclass.
If the types are different, the result is overloading not overriding.
file:Main.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
package subclass.overload; class A { public void m(String s) { System.out.println("A"); } } class B extends A { public void m(Object o) { System.out.println("B"); } } class Main { private Main() {} public static void main(String[] args) { String y = "?"; Object x = y; B b = new B(); A a = b; a.m(y); // a.m(x); b.m(y); b.m(x); } }