1Z0-811 Java Operators and Control Flow Flashcards
6 cards from real 1Z0-811 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 1Z0-811 Java Operators and Control Flow flashcards as text
What is the difference between `==` and `.equals()` when comparing String objects in Java?
Answer: `==` compares references; `.equals()` compares content
`==` compares object references (memory addresses), while `.equals()` on String compares the actual character content.
Which loop is guaranteed to execute its body at least once?
Answer: do-while loop
The `do-while` loop evaluates its condition after executing the body, so it always runs at least once regardless of the condition.
What is the correct syntax for a `switch` statement's default case in Java?
Answer: default: { }
The `default` keyword in a switch statement defines the block that executes when no other case matches.
Which of the following correctly describes the `break` statement in a `switch` block?
Answer: It prevents fall-through to the next case
Without a `break` statement, execution falls through to the next case in a switch block; `break` prevents this by exiting the switch.
What is the output of `int i = 0; while(i < 3) { System.out.print(i + " "); i++; }`?
Answer: 0 1 2
The loop prints i (starting at 0) and increments it after each print, running while i < 3, so it outputs 0, 1, and 2.
What does the compound assignment operator `+=` do?
Answer: Adds the right operand to the left operand and assigns the result to the left operand
The `+=` operator adds the right operand to the left operand and stores the result back in the left operand (e.g., `x += 3` is equivalent to `x = x + 3`).