I have a doubt in Dan's exam ...Consider the following piece of code :
class A {
public static void main (
String args[]) {
byte primitiveByte = 1;
int primitiveInt = 1;
long primitiveLong = 1L;
float primitiveFloat = 1f;
String s = "1";
Long i1 = new Long(primitiveByte);
Long i2 = new Long(primitiveInt);
Long i3 = new Long(primitiveLong);
Long i4 = new Long(primitiveFloat);
Long i5 = new Long(s);
int i6 = i1.intValue() + i2.intValue() +
i3.intValue() + i4.intValue() +
i5.intValue();
System.out.print(i6);
}
}
What is the result of attempting to compile and run the program?
a. Prints: 5
b. Prints: 5.0
c. Compiler Error
d. Runtime Error
e. None of the Above
Answer : c
Can anyone explain how ? Also , his explanation says conversion from float to long a widening conversion and not narrowing conversion. Is that so ?