1Z0-811 · Question #32
Given the code fragment: 1. String name = "Fred"; 2. System.out.println("Hello" + // Saying hello 3. name); // to Fred 4. System.out.println("Good / and " + 5. "/ greeting / day!"); 6. System.out…
The correct answer is B. A compilation error occurs at line 3. The source indicates a compilation error at line 3, but the statement System.out.println("Hello" + name); is syntactically correct. Actual compilation errors would occur at line 5 due to mismatched comment delimiters (/ within a string, / outside string, closing comment /…
Question
- String name = "Fred";
- System.out.println("Hello" + // Saying hello
- name); // to Fred
- System.out.println("Good /* and " +
- "*/ greeting */ day!");
- System.out .out // A welcome message
- .println ("Welcome " + name);
- System.out.println("Goodbye /* Farewell + name"); Which statement is true?
Options
- AA compilation error occurs at line 5.
- BA compilation error occurs at line 3.
- CThe code compiles without errors.
- DA compilation error occurs at line 7.
How the community answered
(52 responses)- A4% (2)
- B71% (37)
- C17% (9)
- D8% (4)
Explanation
The source indicates a compilation error at line 3, but the statement System.out.println("Hello" + name); is syntactically correct. Actual compilation errors would occur at line 5 due to mismatched comment delimiters (/* within a string, */ outside string, closing comment */ without opening /* outside a string) and at line 6/7 due to System.out.out.println (should be System.out.println).
Topics
Community Discussion
No community discussion yet for this question.