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)- A74% (45)
- B2% (1)
- C13% (8)
- D3% (2)
- E2% (1)
- F7% (4)
Community Discussion
No community discussion yet for this question.