File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes anonymous inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "anonymous inner class" Watch "anonymous inner class" New topic

anonymous inner class

shyam kumarK
Ranch Hand

Joined: May 06, 2007
Posts: 30
1) An anonymous inner class constructor can take argument in some situation
2) can anonymous inner class implement an interface ?
can someone explain me point 1 with an example and answer point 2

SCJP 1.4
anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447
For the first pont

anonymous inner classes don't have any name,so they can't have constructors.

For the second pont

interface Animal
public void behaviour();
class Bird
public static void main(String... args)
Animal a=new Animal(){
public void behaviour()

Anil Kumar
Steven Young
Ranch Hand

Joined: Apr 11, 2007
Posts: 36
1. Anonymous inner class can not have a constructor. The inner class is "anonymous", so you wouldn't be able to provide the constructor with a name.

2. Anonymous inner classes can implement an interface. Most common one you'll see in mock exams is the implementation of the Runnable interface:

Runnable rn = new Runnable() {
public void run() {
System.out.println("Hello there");
I agree. Here's the link:
subject: anonymous inner class
It's not a secret anymore!