What will be printed as a result of compiling and running the following code?

public class Test {
    private static Boolean b1, b2;
    
    public static void main (String[] args) {
        if (b1 || !b2 || !b1 || b2) {
            System.out.println(true);
        }
        else {
            System.out.println(false);
        }
    }
}
Explanation
When using wrapper objects in operations designed for primitives, the methods that return a primitive value are called. In this case booleanValue(). This will cause throwing of NullPointerException.

Follow CodeGalaxy

Mobile Beta

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