Menu
Question Index
...

What will be the output of the following program?

public class VarScope {
    public static void main(String[] args) {
        int x = 10;
        {
            int y = 20;
            System.out.print(x + ", " + y);
        }
        {
            y = 10;
            x = 15;
            System.out.print(" - " + x + ", " + y);
        }
        System.out.print(" - " + x + ", " + y);
    }
}


10, 20 - 15, 10 - 15, 10
10, 20 - 15, 20 - 10, 20
10, 20 - 15, 20 - 15, 20
Compilation Error
Runtime Error

Doubts

Problems

Topic: Scope Of Variables In Nested/Multiple Blocks

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App