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?

  1. A.

    10 Child: 20

  2. B.

    20 Parent: 10

  3. C.

    20 Child: 20

  4. D.

    10 Parent: 10

Attempted by 23 students.

Sign up free to check your answer

Sign up free

Explore the full course: Isro

Loading lesson…