Which code fragment causes a compilation error?

Which code fragment causes a compilation error?

A. Option A
B. Option B
C. Option C
D. Option D
E. Option E

Download Printable PDF. VALID exam to help you PASS.

6 thoughts on “Which code fragment causes a compilation error?

  1. D:
    # javac Test33.java
    Test33.java:10: error: possible loss of precision
    float flt = y1;
    ^
    required: float
    found: double
    1 error
    ———————–
    to compile without error its needed casting: float flt = (float) y1

  2. Answer D:

    By default, any decimal point number is of type “double”. Therefore, whenever we assign a decimal number to a float variable, we either have to use “f” postfix, or to cast that number to (float).

  3. public class Test {
    public static void main(String[] args) {
    float flt = 100F;
    float flt1 = (float) 1_11.00;
    float flt2 = 100;
    double y1 = 203.00;
    float flt3 = y1; //Type mismatch: cannot convert from double to float
    int y2 = 100;
    float flt4 = y2;
    }
    }

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.