Consider the following Java code: class Parent { int x = 10; void show() {…
BEL Probationary Engineer 2025
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?
- A.
10 Child: 20
- B.
20 Parent: 10
- C.
20 Child: 20
- D.
10 Parent: 10
Attempted by 23 students.
Sign up free to check your answer
Sign up freeLoading lesson…

