• 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

puzzle of inner class

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found in many exams says that you can't instantiate an non-static inner class without an instance of the outer class. but pls. look at the following code

i compile an run the program cleanly
any comment?

[This message has been edited by James Du (edited July 06, 2001).]
 
James Du
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe i missed out one thing:
should a inner class declared in the static methods be regarded non-static inner class?
[This message has been edited by James Du (edited July 06, 2001).]
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the inner class here is within a static method, which makes it a static local class.

Originally posted by James Du:
maybe i missed out one thing:
should a inner class declared in the static methods be regarded [b]non-static inner class
?
[This message has been edited by James Du (edited July 06, 2001).][/B]


 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
'inn' is a local inner class. Local inner classes are not members, they do not belong to the enclosing class and can only be seen within the block in which they are declared. The 'static' modifier isn't all that important here.
The only place you can instantiate a local inner class object is within the code block where it was declared. See JLS §14.3
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic