Multiple choice java

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

Option D constructs and uses an anonymous inner class instance of Runnable by passing it directly to the println method. Options A and B are syntax errors (A is missing a body or needs braces; B has invalid syntax inside parens), and Option C is missing parentheses required for the constructor invocation.