class First {
public Object method1() {
return new
String("Based");
}
}
class Second extends First {
public String method1() {
return new String("Derived");
}
}
public class covariant {
public static void main(String[] args) {
First o = new Second();
String s = (String) o.method1();
System.out.println(s);
}
}
For the above code, why does it print Derived instead of Based?
The reference variable of o is First and method1 should be called in First instead of Second
Thanks