Multiple choice technology programming languages

Which constructs an anonymous inner class instance?

  1. Runnable r = new Runnable() { };

  2. Runnable r = new Runnable(public void run() { });

  3. Runnable r = new Runnable { public void run(){}};

  4. System.out.println(new Runnable() {public void run() { }});

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This statement compiles because the anonymous inner class correctly implements the required run method of the Runnable interface. The other options fail due to syntax errors, such as missing parenthesis in option 3 or passing Java code as an argument in option 2, or missing implementation of the abstract run method in option 1.