Which code fragment cause a compilation error?

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



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Stephanie

Stephanie

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.

Roger

Roger

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