Given:
and
and
What is the result?
Given:
and
and
What is the result?
In Java, instance variables are not overridden but hidden. In the given code, the instance variable 'x' in class A has the value 42, and the instance variable 'x' in class B has the value 17. When a reference of type A is used to access the variable 'x' (even if the reference points to an instance of B), it accesses the 'x' variable declared in class A. Therefore, the output of the program is 42.
A is correct you cannot override instance variables
A is correct because, constructor has a protected modified, so child class can see that constructor, and instance variables not override. if father class has a default access this would be a compilation error cause chid class cannot see the super constructor of father class
the static method and variables are acceses by the Type of object not the real object. so x in A is acceded. if B obj = new B(); => then x in b is printed
Tested: A!
Answer:A
A is correct
42 will be output