• 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

Anonymous classes

 
Ranch Hand
Posts: 203
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,

I was going through the concept of Anonymous classes and Inner classes I, I have one query with regard to Anonymous classes is that if we have a super class and we want to override the method of superclass but without subclassisng means without following inheritance then in that case the Anonymous class is the only option..?

Secondly whats the purpose of introducing the Anonymous class in java technically please justify ..!!!
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean, without inheritance? Anonymous classes are exactly the same as other classes that extend some super class. The difference is that anonymous classes have no name. Inheritance works as usual.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saral Saxena wrote:Secondly whats the purpose of introducing the Anonymous class in java technically please justify ..!!!


In my opinion, the purpose is to provide yet another way to structure the code. Anything you can do with anonymous classes can be done with other types classes as well. Anonymous classes allow you to save a few keystrokes, as well as to place related pieces of code closer together. The latter reason is probably much more important of the two.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Saral Saxena wrote:...and we want to override the method of superclass but without subclassisng...


The statement is fallacious: you cannot override the method of superclass without subclassing. An anonymous class is a subclass; it's just not a named type.

Winston
 
reply
    Bookmark Topic Watch Topic
  • New Topic