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
Зареєструйся Зараз
або Підпишись на майбутні тести