Imagine we have one interface and these classes:
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")
}
}
Enter fullscreen mode Exit fullscreen mode
And then we execute this piece of code
SuperType superType = new ChildOfSuperType();
DefaultSuperType defaultSuperType = (DefaultSuperType) superType;
defaultSuperType.test()
Enter fullscreen mode Exit fullscreen mode
Do you know what will be printed?
© 版权声明
THE END
暂无评论内容