nerdexam
Oracle

1Z0-851 · Question #30

Given: public static void test(String str) { int check = 4; if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", "); } else { System.out.print(str.charAt(0) + ", "); } } and the…

The correct answer is C. Compilation fails. See the full explanation below for the reasoning.

Question

Given: public static void test(String str) { int check = 4; if (check = str.length()) { System.out.print(str.charAt(check -= 1) +", "); } else { System.out.print(str.charAt(0) + ", "); } } and the invocation: test("four"); test("tee"); test("to"); What is the result?

Options

  • Ar, t, t,
  • Br, e, o,
  • CCompilation fails.
  • DAn exception is thrown at runtime.

How the community answered

(57 responses)
  • A
    4% (2)
  • B
    7% (4)
  • C
    72% (41)
  • D
    18% (10)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice