Menu
Topics Index
...
`

TypeConversion2 test


If you need explanation Read this topic

If you need Answer Take test on this topic

TypeConversion2 test
What will be the output of the following program?
public class TypeConversion2 {
    public static void main(String... strings) {
        byte i = 21;
        long s = 12345678;
        int b = 256;
        short l = 4310;
        String st = "58.99";
        s = b;
        b = l;
        l = i;
        i = (byte) (Double.parseDouble(st) + i);;
        System.out.println("b = " + b + " s = " + s + " i = " + i + " l = " + l);
    }
}

A. b = 4310 s = 4310 i = 80 l = 21
B. b = 4310 s = 4310 i = 79 l = 21
C. b = 4310 s = 256 i = 80 l = 21
D. b = 4310 s = 256 i = 79 l = 21
E. Compilation Error or Runtime Error
Topic: Java Collections - Utility Classes 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 d : b gets value of l  i.e, 4310 and s gets value of b i.e, 256 ni gets value 58.99 +21 i.e, 79.99 which gets converted to 79 and l gets i i.e, 21

Posted by Pramod Jain    2013-05-20 12:53:11


answer is d

Posted by Aparna Kanjarla    2013-05-20 12:59:57


since java supports automatic type conversion all this conversions except st to i so for that we do explicit type conversion by specifying byte in braces

Posted by Aparna Kanjarla    2013-05-20 13:03:28


Congratulations Pramod Jain. You are today's daily dose winner. Please send us your mobile details and we will process the recharge tomorrow after considering the new likes.

Posted by Merit Campus    2013-05-20 15:31:22


got rc :) thank u mc :)

Posted by Pramod Jain    2013-05-21 15:06:05


© meritcampus 2019

All Rights Reserved.

Open In App