Представьте, что у нас есть один интерфейс и эти классы:
interface SuperType { void test(); } class DefaultSuperType implements SuperType{ @Override void test(){ System.out.println("0") } } class ChildOfSuperType extends DefaultSuperType{ @Override void test(){ System.out.println("1") } }
А затем мы выполняем этот фрагмент кода
SuperType superType = new ChildOfSuperType(); DefaultSuperType defaultSuperType = (DefaultSuperType) superType; defaultSuperType.test()
Вы знаете, что будет напечатано?
Оригинал: “https://dev.to/devit951/java-inheritance-puzzle-446j”