| preferred AP College board partner for AP classes
easy
Logical Operators in If Conditions
< Prev
Next >

What is the error that prevents this code from compiling?

public class Test {
    public static void main(String[] args) {
        boolean a = true, b = false;
        if(a, b) {
            System.out.println("Invalid operator usage");
        }
    }
}
A

The if condition incorrectly uses a comma to separate boolean expressions instead of a proper logical operator.

B

The main method signature is invalid.

C

The boolean variables a and b are declared in the wrong order.

D

The System.out.println statement should be enclosed in braces.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy