aspose file tools*
The moose likes Beginning Java and the fly likes Example of anonumous class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Example of anonumous class" Watch "Example of anonumous class" New topic
Author

Example of anonumous class

Jayavardhan geepi
Ranch Hand

Joined: Jul 21, 2010
Posts: 66
Hi, can anybody give me simple example of anonymous classes in java?
Example with custom type is appreciated. Thanks...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Jayavardhan geepi wrote:Hi, can anybody give me simple example of anonymous classes in java?

first[google it],come up with some example yourself .
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
There was a thread about that on JavaRanch yesterday, I think in Java in General.
Jayavardhan geepi
Ranch Hand

Joined: Jul 21, 2010
Posts: 66

Is independent anonymous class possible? I mean , an anonymous class that neither extend any class nor implement any interfaces...

@ Campbell,

There is a thread , but that will not help me.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Jayavardhan geepi wrote:
Is independent anonymous class possible? I mean , an anonymous class that neither extend any class nor implement any interfaces...

No. In the end there is always java.lang.Object as the root of every class hierarchy. But you can make anonymous subclasses of Object. The only thing is, unless you override equals, hashCode, toString or finalize this anonymous subclass will be pointless. Overriding clone is senseless as the class wouldn't implement Cloneable, and all other methods are final. Without overriding any of these 4 methods your anonymous subclass will behave exactly like Object itself.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Example of anonumous class