• 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

Nested Classes

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, I need a resource that carefully explains the difference between static nested class, inner class and anonymous classes.

Thanks in advance.
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An inner class is a class declared within another class. For example:



An inner class is considered a member of the outer class. As a result, it can be marked with all 3 access modifiers (public, private, protected). You need an instance of the outer class in order to instantiate an instance of the inner class. For example:



OR



A warning, though, inner classes CANNOT have any static declarations, be it variables or methods. Also, remember that an inner class has access to members of the outer class. That's it for inner class.

An anonymous inner class is simply an inner class without a name. It can extend exactly onc class, or implement exactly one interface, but not both at the same time. The form is:



"Something" can be either a class or an interface. An anonymous inner class is simply either a subclass or an interface implementor that is declared without a name.

For static nested classes, it's similar to a regular inner class, except that the class itself is marked with the static modifier, like this:



A nested class can be instantiated as follows:



A nested class can have both instance and class members. It bears no relationship with the outer class.

Hope this helps.
[ February 03, 2005: Message edited by: Liang Anmian ]
 
Udegbunam Morah
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liang Anmian,
That's a wonderful post. Summarized all I need to know.
Thanks a lot.
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really very good Liang ,
Thank you very much ...
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic