There is only one case where this will work, as mentioned by xamde , but not fully explained. This is due to covariant return types .
In JDK 5, the covariant returns to where it is added, and as such is a valid case that will compile and run without problems.
public interface A { public CharSequence asText(); } public interface B { public String asText(); } public class C implements A, B { @Override public String asText() { return "C"; } }
Therefore, the following will execute without errors and print "C" on the main output:
A a = new C(); System.out.println(a.asText());
This works because String is a subtype of CharSequence.
source share