Topics Index

Byte Conversion

If you need explanation Read this topic

If you need Answer Take test on this topic

Byte Conversion
What will be the output of the following program?
public class ByteDemo {
    public static void main(String[] args) {
        Byte bt = new Byte((byte) 'A');
        byte b = bt.byteValue();
        String str = "Primitive byte value of Byte object: " + bt + " " + "is" + " " + b;

A. Primitive byte value of Byte object: 65 is 95
B. Primitive byte value of Byte object: 65 is 65
C. Primitive byte value of Byte object: 33 is 65
D. Primitive byte value of Byte object: 65 is 21
E. Compilation Error or Runtime Error
Topic: Creating Objects for Primitive Data Types (Byte, Short)

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.

Ans is we have Concept of Type conversion..
here we have the explicit type conversion..when we need to convert higher data type to lower data type than we need to use the type casting...
Implicit type conversion will automatically done by the will occur when we are converting lower data type to higher type..

here we are type converting 'A' into byte so it will give the ASCII value of the A which is 65..we passed it to the Byte() constructor..
next we are receiving these value into byte primitive variable using the byteValue() which returns the byte values as primitive from the object..
now bt will have the 65 and we are inserting into the String and printing..

Posted by Uday Kumar    2014-12-12 03:53:48

This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Sai Ram,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Shubham Bansal. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2014-12-14 01:45:31

© meritcampus 2019

All Rights Reserved.

Open In App