nerdexam
Oracle

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 /…

Basic Java Elements

Question

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 .out // A welcome message
  7. .println ("Welcome " + name);
  8. 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)
  • A
    4% (2)
  • B
    71% (37)
  • C
    17% (9)
  • D
    8% (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

#Java comments#string literals#compilation errors#Java syntax

Community Discussion

No community discussion yet for this question.

Full 1Z0-811 Practice