Consider the following Java code: class Parent {
Consider the following Java code:
class Parent {
int x = 10;
void show() { System.out.println("Parent: " + x); }
}
class Child extends Parent {
int x = 20;
void show() { System.out.println("Child: " + x); }
}
public class Test {
public static void main(String[] args) {
Parent obj = new Child();
System.out.println(obj.x);
obj.show();
}
}
What will be the output of this program?
Show answerHide answer
Correct answer: (D) 10 Child: 20