• 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

Static Nested Classes

 
Ranch Hand
Posts: 59
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Quote from KnB Book:
"Look for static nested classes with
code that behaves like a nonstatic (regular inner) class."



I din't get this at all. Please explain this line.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the differences between static inner classes and non-static inner classes. Remember that inner classes have a 'special' relationship with their outer classes.

Inner classes are able to make full use of the instance variables present in their outer classes (even private variables).

Static inner classes can be used without requiring an instance of the outer class that they live in, and as a result a static inner classes might be used when there is no instance of the outer class. If there's no outer class instance, then there are no outer class instance variables to utilise. As a result, static inner classes can only access the static variables present in their outer class.

That's one way a static inner class might misappropriately behave like a regular inner class (there's probably more examples too).
 
nitin sethi
Ranch Hand
Posts: 59
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it. Thanks Sam.
 
reply
    Bookmark Topic Watch Topic
  • New Topic