Menu
Topics Index
...
`

Integer conversion output106


If you need explanation Read this topic

If you need Answer Take test on this topic

Integer conversion output106
What will be the output of the following program?
class IntegerConversion
{
    public static void main(String args[])
    {
        long l = 55;
        int i = 44;
        short s = 33;
        byte b    = 22;
        
        i = l;
        s = i;
        b = s;

        System.out.println("l = " + l);
        System.out.println("i = " + i);
        System.out.println("s = " + s);
        System.out.println("b = " + b);
    }
}

A. l = 55
i = 44
s = 33
b = 22
B. l = 22
i = 33
s = 44
b = 55
C. l = 55
i = 55
s = 55
b = 55
D. Program does not compile.
Topic: Type Conversion 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.

C

Posted by Sreenath Vallapaneni    2014-04-07 04:20:53


Because 55 is copied to all the variables

Posted by Sreenath Vallapaneni    2014-04-07 04:21:56


Ans is c all variables will have same value as it copied from one variable to other

Posted by Bharath Yelchuri    2014-04-07 05:44:11


Ans is C..as the values in the corresponding variables are overwritten by 55

Posted by Badam Swathi    2014-04-07 09:38:39


No winner for this dose. Correct option is 'D' :(.

Posted by Merit Campus    2014-04-08 03:58:49


Y

Posted by Sreenath Vallapaneni    2014-04-08 04:31:15


This program gives compilation error because since long can not be assigned to int and similarly int can not be assigned to short and short can not be assigned to b.

Posted by Merit Campus    2014-04-08 11:08:25


© meritcampus 2019

All Rights Reserved.

Open In App