Constructs an anonymous inner class instance - Java

Q.  Which constructs an anonymous inner class instance? (Java)
- Published on 26 Jun 15

a. Runnable r = new Runnable() { };
b. Runnable r = new Runnable(public void run() { });
c. Runnable r = new Runnable { public void run(){}};
d. System.out.println(new Runnable() {public void run() { }})

ANSWER: System.out.println(new Runnable() {public void run() { }})
 
The anonymous classes enables to make the code more concise. It enables to declare and instantiate a class at the same time. They are like local classes but they do not have a name.
 

    Discussion

  • temesgen   -Posted on 18 Apr 21
    good

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)