None of them overrides A'a's superclass method.
class A { public void foo(A a) { System.out.println("in A"); } } class B extends A { @Override public void foo(B b) { System.out.println("in B"); } @Override public void foo(Object o) { System.out.println("in B"); } }
When compiling the above, I get errors:
$ javac -g O.java O.java:10: method does not override or implement a method from a supertype @Override ^ O.java:14: method does not override or implement a method from a supertype @Override ^ 2 errors
But note that it is normal to return a subclass from an override method. The following compilation without errors.
class A { public A foo() { System.out.println("in A"); return this; } } class B extends A { @Override public B foo() { System.out.println("in B"); return this; } }
source share