Menu
Topics Index
...
`

Life Time


If you need explanation Read this topic

Life Time
What will be the output of the following program?
public class LifeTime {
    public static void main(String[] args) {
        if (true) {
            int x = 10;
            System.out.println("Value of X = " + x);
            x++;
        }
        System.out.println("Value of X = " + x);
    }
}

A. Value of X = 10
Value of X = 11
B. Value of X = 10
Value of X = 0
C. Value of X = 10
Value of X = 10
D. Compilation Error
E. Runtime Error
Topic: Lifetime Of Variable In Java

If you need explanation Read this topic

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

D. Compilation error....because 'x' is declared inside if statement .The value of 'x' can't be accessed outside that statement....

Posted by Sagar Kamble    2014-01-17 04:06:56


answer is a

Posted by Shiva Goud    2014-01-17 04:07:10


answer is b

Posted by Kishan Viru    2014-01-17 07:59:30


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

Posted by Merit Campus    2014-01-20 04:15:12


© meritcampus 2019

All Rights Reserved.

Open In App