What will be the result of the following code compilation and execution?

public class Base {

    public Object print() {
        return "Object from base method";
    }

    public static void main(String[] args) {
        Base test = new Child();
        System.out.println(test.print());
    }

}

class Child extends Base {

    public String print() {
        return "String from child method";
    }
}
Explanation
Overridden method of the derived class may return a type derived from the type returned by the base class method.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты