Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

inner class

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In a mock test i was seeing the following question

which is true regarding Inner Class

the right ANSWERES where

a) An instance of a top level nested class can be created with out an instace of its enclosing class

b) to create an instance of a member class an instance of its enclosing class is required


I'm not able to relate the ans (a)


IT would be great if any one could explain it with an example........!!!1
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

An instance of a top level nested class can be created with out an instace of its enclosing class



it means if you are creating the object of inner class within any method of outer enclosing class you don't need the instance of Outer class.

Consider this example::

 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Yogesh!

Sorry, but the example of Priyam is completely wrong. It is a regular inner class, not a top level nested class. And despite the comment "no outer ref. needed" it IS needed, as you can see in the main method.

A "top level nested class" is just the same as a "static inner class".

The first terminus is official and more correct since these static inner classes aren't real inner classes at all.


Do you still need an example or do you understand this already?

Bu.
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops!!! mistake accpeted !! thanks for a reminder..

i should have written this::

 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
yogesh srinivasan
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Burkhard Hassel

A "top level nested class" is just the same as a "static inner class".




Need some more explanation for the above statement as i cant relate them.... ;


More over i need to know wat is the need for static class...and how the constructors behave for this context when compared to a normal class
[ August 06, 2007: Message edited by: yogesh srinivasan ]
 
it's a teeny, tiny, wafer thin ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic