• 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 Class Query

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LINK: http://www.danchisholm.net/july21/mybook/chapter13/exam1.html

Question 23

A compile-time error is generated at which line?

The answer is Line 6. Why not Line 5. I want an explanation please.

Why the query came to my mind is, a Static inner class is loaded whether or not the enclosing class' instance exist.

Suppose I just instantiate a 'StaticNested' class. Now the class loaded in the JVM is only the 'StaticNested' class and no instance of the enclosing class exist. So, how will the static variable 'b' of the enclosing class be available to the 'StaticNested' class' instance.

Or, if I have wrong interpretations about what all classes are loaded at runtime and about JVM, please explain me on the same. Thanks!
[ October 27, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Loading a class is not the same thing as creating an instance of the class. Both classes are loaded even though you may have only created an instance of the static inner class.

The static inner class can only access static members of its enclosing class.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic