nerdexam
Oracle

1Z0-851 · Question #226

Given: interface TestA { String toString(); } public class Test { public static void main(String[] args) { System.out.println(new TestA() { public String toString() { return "test"; } }); } } What…

The correct answer is A. test. See the full explanation below for the reasoning.

Question

Given: interface TestA { String toString(); } public class Test { public static void main(String[] args) { System.out.println(new TestA() { public String toString() { return "test"; } }); } } What is the result?

Options

  • Atest
  • Bnull
  • CAn exception is thrown at runtime.
  • DCompilation fails because of an error in line 1.
  • ECompilation fails because of an error in line 4.
  • FCompilation fails because of an error in line 5.

How the community answered

(61 responses)
  • A
    74% (45)
  • B
    2% (1)
  • C
    13% (8)
  • D
    3% (2)
  • E
    2% (1)
  • F
    7% (4)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice