What is the result of the following code compilation and execution?

public class Test {
    public static void main(String[] args) {
        float f = 1.0 + 1.0f;
        f = f + 1;
        System.out.println(f / 0);
    }
}
Explanation
Compilation error will occur in line

float f = 1.0 + 1.0f;
Right-hand side expression is of double type and it may not be implicitly converted to the left-hand side variable type (float).

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes