Multiple Choice Question

Quiz Guidelines

 

QID: 
97
Question: 

What happens when you try to compile and run the following program?

public class CastTest{
public static void main(String args[ ] ){
byte b = -128 ;
int i = b ;
b = (byte) i;
System.out.println(i+" "+b);
}
}

Select 1 option 

A. The compiler will refuse to compile it because i and b are of different types cannot be assigned to each other.
B. The program will compile and will print -128 and -128 when run.
C. The compiler will refuse to compile it because -128 is outside the legal range of values for a byte.
D. The program will compile and will print 128 and -128 when run.
E. The program will compile and will print 255 and -128 when run.

Q&A Set: