• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Example of anonumous class

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, can anybody give me simple example of anonymous classes in java?
Example with custom type is appreciated. Thanks...
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


first[google it],come up with some example yourself .
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There was a thread about that on JavaRanch yesterday, I think in Java in General.
 
Jayavardhan geepi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic