Menu
Topics Index
...
`

Static variables


If you need explanation Read this topic

If you need Answer Take test on this topic

Static variables
What will be the output of the following program?
public class LongDivision {
    private static final long VALUE1 = 24 * 60 * 60 * 1000;
    private static final long VALUE2 = 24 * 60 * 60 * 1000 * 1000;
    public static void main(String[] args) {
        System.out.print(VALUE2 / VALUE1);
    }
}

A. 5
B. 1000
C. 5000
D. Some other output
E. Compilation Error or Runtime Error
Topic: Static Keyword In Java

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.

Answer is c

Posted by Shiva Goud    2014-07-11 03:53:21


Ansisb..24*60*60*1000=86400000

24*60*60*1000*1000=86400000000soansis1000

Posted by Uday Kumar    2014-07-11 04:12:11


B

Posted by Sirajudeen Nowshath    2014-07-11 08:40:34


Answer A

Posted by Rupesh Reddy    2014-07-11 12:37:00


B

Posted by Arul Palanisamy    2014-07-11 12:37:01


private static variable

Posted by Rupesh Reddy    2014-07-11 12:41:56


ans A

Posted by Rupesh Reddy    2014-07-11 12:42:05


Here, the expression 24*60*60*1000*1000 would be evaluated as an integer value, not a long value. In fact, this value doesn't fit into an int. So, it is truncated to an int value. But a long could store that value. Since we have forgotten to tell the compiler to do a long division instead of an int division, VALUE2/VALUE1 would yield "5" (24*60*60*1000 = 86400000 and 24*60*60*1000*1000 = 500654080). VALUE2 is not 86400000000 here, it is 500654080 since we have forgotten to add suffix L to int literals in the expression initializing VALUE2 (VALUE1 as well, though there isn't any issue with VALUE1 in this case). We can observe this if we try to print the value of VALUE2. So, the answer is A.

Posted by Shaileshwar Sharma    2014-07-11 13:52:25


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

Posted by Merit Campus    2014-07-14 11:58:56


© meritcampus 2019

All Rights Reserved.

Open In App