File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Anonymous Inner Class" Watch "Anonymous Inner Class" New topic
Author

Anonymous Inner Class

sean cee
Ranch Hand

Joined: Oct 24, 2000
Posts: 115
Hi guys,
I came across a question saying that "An anonymous inner class can be created inside a method" is false....
where else can it be created then?
Thanks


Sean <br />SCJP2, SCJP2p1.4, SCWCD
Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
"An anonymous inner class can be created inside a method"
is TRUE.
Consider the following code:
public A aMethod(){
return new A(){
....
};
}
Here in method aMethod(), an anonymous class wich extends class A is defined.

sean cee
Ranch Hand

Joined: Oct 24, 2000
Posts: 115
Bin,
you are right.
anoymous inner class CANNOT be created anywhere outside the method ... right?
thanks.
Subha Guhan
Greenhorn

Joined: Nov 06, 2000
Posts: 23
Sean

Are you reproducing the question verbatim?
It is not only possible to create it inside the method but also in the following ways.

please correct me if I am wrong
[This message has been edited by Subha Guhan (edited November 07, 2000).]
[This message has been edited by Subha Guhan (edited November 07, 2000).]
sean cee
Ranch Hand

Joined: Oct 24, 2000
Posts: 115
Hi,
Subha, You are right.
your code make good sense.
Thanks
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Anonymous Inner Class
 
Similar Threads
Is this correct?
Anonymous class
anonymous class
Anonymous class
Inner Class