Menu
Topics Index
...
`

Scope2611


If you need explanation Read this topic

If you need Answer Take test on this topic

Scope2611
What will be the output of the following program?
public class Scope {
    public static void main(String[] args) {
        int a = 0;
        {
            int b = 10;
            System.out.println("b = " + b);
            int c = b + a;
            System.out.println("c = " + b);
        }
        a = c + b;
        System.out.println("a = " + a);
    }
}

A. a = 20
b = 10
c = 10
B. b = 10
c = 20
a = 10
C. b = 10
c = 10
a = 20
D. Compilation Error
E. Runtime Error
Topic: Scope Of Variables In Nested/Multiple Blocks

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

at 10th line scope of b and c is out of scope because there are declared inside the inner block and hence there is a compilation error therefore answer is d

Posted by Sangeetha Ptl    2014-03-26 12:53:23


ans is d since the scope of b and c is out at a=b+c line so it results compilation error

Posted by Naga Sinst    2014-03-26 14:27:14


Congratulations Sangeetha Ptl. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-03-27 04:20:22


© meritcampus 2019

All Rights Reserved.

Open In App