OverrideTest.java
/**
* An example of using @overrides to have the compiler check that
* you have correctly overridden a method. In particular, this example
* will not compile because the ping method in D does not have the
* same argument types as the ping method in C.
*
* @author Jim Glenn
* @version 0.1 3/28/2008
*/
public class OverrideTest
{
public static void main(String[] args)
{
A a = new B();
D d = new D();
System.out.println(d.ping(a));
}
}
class A
{
}
class B extends A
{
}
class C
{
public String ping(A a) { return "ping"; }
}
class D extends C
{
@Override
public String ping(B a) { return "pong"; } // argument must be of type A
}
This code can also be downloaded from the file
OverrideTest.java.