Java Inheritance Puzzle
Ildarov
Posted on April 2, 2019
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")
}
}
And then we execute this piece of code
SuperType superType = new ChildOfSuperType();
DefaultSuperType defaultSuperType = (DefaultSuperType) superType;
defaultSuperType.test()
Do you know what will be printed?
💖 💪 🙅 🚩
Ildarov
Posted on April 2, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.