• 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

Inner class references

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Out of several questions/answers from mock exam I made up the follwing rules:
A non-static inner class reference needs an instance of its enclosing class!

A static inner class reference does not need an instance of the enclosing class!

Can I take this for granted?
Erik Dark
[ February 01, 2002: Message edited by: Erik Dark ]
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code examples are correct, and I understand what you mean, but your terminology is a little off.
There is no such thing as a "static inner-class".
There are nested classes - that's just any class that's defined inside another class or interface.
An inner class is a special type of nested class - it requires an instance of its enclosing class to exist for it to exist.
A static nested class is just that- it's a top level class that's defined inside another class, and you must use the name of the enclosing class to reference it outside of the enclosing class, but since it's top level (static), you don't need to create an instance of the enclosing class.
So...remember, it's either an inner class, or a static nested class. No such thing as "static inner class".
Rob
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic