HTML & JS
class A {}

class B extends A {}

class Base
{
    B fun()
    {
        System.out.println("Base fun()");
        return new B();
    }
}

class Derived extends Base
{
    A fun()
    {
        System.out.println("Derived fun()");
        return new A();
    }
}

public class Main
{
    public static void main(String args[])
    {
       Base base = new Base();
       base.fun();

       Derived derived = new Derived();
       derived.fun();
    }
}

Generated URL:

Warnings:

16: error: fun() in Derived cannot override fun() in Base
    A fun()
      ^
  return type A is not compatible with B
1 error

Output:

No Output
Report Bug