The answer is C and D.
A. float flt = 100.00F; // correct
B. float flt = (float) 1_11.00; // correct
C. Float flt = 100.00; // assigning a double to Float object without explicit cast
D. double y1 = 203.22; float flt = y1; // assigning a double to a float without explicit cast
E. int y2 = 100; float flt = (float) y2 ; // correct
Answer is CD.
To test, uncomment one option at a time in the IDE and check the error.
public static void main(String[] args) {
//float flt = 100.00F; // A - Ok
//float flt = (float) 1_11.00; // B - Ok
//Float flt = 100.00; // C - Error - need cast to Float.
//double y1 = 203.22; float flt = y1; // D - Error - need cast to float.
//int y2 = 100; float flt = (float) y2 ; // F - Ok
}
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
fvelazqueznava
3 months, 1 week agoDarGrin
3 months, 1 week agoanastacia
3 months, 1 week agoIbrahimAlnutayfi
6 months, 3 weeks agoVicky_65
9 months, 2 weeks agoHirushi
11 months, 1 week agoakbiyik
1 year, 1 month agoakbiyik
1 year, 1 month agocarloswork
1 year, 2 months agoiSnover
1 year, 3 months agoiSnover
1 year, 3 months agoshivkumarx
1 year, 4 months agoshivkumarx
1 year, 4 months ago