• 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

innerclass

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mughal's page 226 says
Since nested top-level classes are static, there methods do not have any (outer) instance of the enclosing context.
to understand the above i wrote this code below

am makeing an instance of the Enclosing class (TopLevel) in the nested class and calling meth from the enclosing class,
dont you think according to Mughal's i should get a compile time error ?
or my example is wrong, if wrong can you give an example to understand Mughal's please...
Thanks in Advance
[ Jess added UBB [CODE] tags to preserve whitespace -- check them out! ]
[ July 16, 2002: Message edited by: Jessica Sant ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I think you're just confusing the terms a bit. You are still free to create an instance of the enclosing class within a top-level nested class, but, with an inner class, you must have an instance of the enclosing class before you can create an instance of the inner class.
As an instance of the enclosing class must be created prior to the instance of the inner class, all true inner classes have an implicit reference to the instance of the enclosing class. Therefore, you can use a modified version of the keyword this, like this, to access members of the enclosing context:

That implicit reference to the enclosing instance doesn't exist in a top-level nested class because the class can be instantiated without an instance of the enclosing class, like this:

As you can see, I didn't need to make an instance of the class Test prior to instantiating the class TopLevelNested. I was required to do so in the previous example.
I hope that helps,
Corey
 
reply
    Bookmark Topic Watch Topic
  • New Topic