Oracle Certified Professional Java Se 11 Developer · Free Practice Question Hard
Question 46
Question ID: UKOCP84358
Given code:
- package com.udayankhattry.ocp;
- interface I1 {
- void m1();
- }
- public class Test {
- public static void main(String[] args) {
- I1 i1 = new I1() {
- @Override
- public void m1() {
- System.out.println(1234);
- }
- }
- i1.m1();
- }
- }
What will be the result of compiling and executing Test class?
- A 1234
- B No output
- C Compilation error
- D Runtime exception
Reveal correct answer
Correct answer: C
Explanation
UKOCP84358:
Semicolon is missing just before the statement i1.m1(); Wrong syntax of anonymous inner class.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
