What is the result of the following program?

public class Test {
    public static void main(String[] args) {
        System.out.println("4/2=" + 4/2 == "4/2=2");
    }
}
Explanation
Division: 4/2 → 2
Typecasting: 2 → "2"
Concatenation "4/2=" + "2" → "4/2=2"
Comparison: "4/2=2" == "4/2=2" → true
All this happens at compilation time, there are no strings in the compiled byte-code.

Follow CodeGalaxy

Mobile Beta

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