Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Anonymous inner class question from dan's test

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In explanation for one of the questions in Dan's test,it is given that If the anonymous class extends another class then the class instance creation expression can include parameters. The parameters will be passed to a constructor of the super class.
I couldn't understand it fully?Can anonymous class(which already extends some class) extend another class??!!!Can anybody explain the above with an example?
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Anonymous classes can not extend another class. They cannot have any constructors declared. The statement should mean that, if you want to call the parameterized constructor of the super class, pass arguments while declaring the instance. Consider this simple code.

Thanks,
Uma....
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another of way of explaining the Dan's statement is that anonymous class can either extend another class or implement an interface. He is saying if it is extending another as apposed to implementing an interface.
reply
    Bookmark Topic Watch Topic
  • New Topic