Which code fragment cause a compilation error?
A.
float flt = (float) 1_11.00;
B.
int y2 = 100; floatflt = (float) y2;
C.
flat flt = 100F;
D.
float flt = 100;
E.
double y1 = 203.22; floatflt = y1
Which code fragment cause a compilation error?
Which code fragment cause a compilation error?
A.
float flt = (float) 1_11.00;
B.
int y2 = 100; floatflt = (float) y2;
C.
flat flt = 100F;
D.
float flt = 100;
E.
double y1 = 203.22; floatflt = y1
The answer is E because you cannot have a float variable pointing to a double variable (incompatible types) unless you do casting like in answer B.
e
E.
B,C,E
B,C,D,E
float flt = (float) 1_11.00; //correct
int y2 = 100; floatflt = (float) y2; //floatflt has no type
flat flt = 100F; //flat is no type
float flt = 100; // 100 is of type integer
double y1 = 203.22; floatflt = y1 //floatflt has no type