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

public class Parent {
    protected String value = "parent";

    public static void main(String[] args) {
        Parent parent = new Child();
        Child child = new Child();
        System.out.println(parent.value);
        System.out.println(child.value);
    }
}

class Child extends Parent {
    protected String value = "child";
}
Explanation
Fields of a class are not overridden as a result of inheritance. Therefore in every case the value of the field of an instance of a class will be printed out.

Следи за CodeGalaxy

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

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