Consider the following Java program: class Demo { int x = 5; static int y =…

BEL Probationary Engineer 2025

Consider the following Java program:

class Demo {
    int x = 5;
    static int y = 10;
    void display() {
        int x = 20;
        System.out.println(x + " " + this.x + " " + y);
    }
}
class Test {
    static int y = 50;
    public static void main(String[] args) {
        Demo d = new Demo();
        d.display();
        System.out.println(d.y + " " + y);
    }
}

What will be the output of the program?

  1. A.

    20 20 10 and 10 10

  2. B.

    20 5 50 and 10 10

  3. C.

    20 5 10 and 10 50

  4. D.

    20 5 10 and 50 50

Attempted by 18 students.

Sign up free to check your answer

Sign up free

Explore the full course: Isro

Loading lesson…