Menu
Question Index
...

What will be the output of the following program?

public class Conversions
{
    public static void main(String args[])
    {
        byte x;
        int a = 270;
        double b = 128.128;
        x = (byte) a;
        System.out.println("a and x " + a + " " + x);
        a = (int) b;
        System.out.println("b and a " + b + " " + a);
        x = b;
        System.out.println("b and x " + b + " " + x);
    }
}


a and x 270 14
b and a 128.128 128
b and x 128.128 -128
a and x 270 14
b and x 128.128 -128
b and a 128.128 128
a and x 270.0 14.0
b and a 128.128 128
b and x 128.128 -128
Compilation Error or Runtime Error

Doubts

Problems

Topic: Type Casting In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App