• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

inner class and outer class

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inner class can automatically able to access all the outer memebrs including private members. What advantage it will get when an inner class extends Outer class ?

Case1:

class outer{
String name;

class inner{//it will be able to access "name" }
}

Case 2:

class outer{
String name;

class inner extends outer {//it will be able to access "name" because it's an inner class }
}

Can anybody explain the advantage in the second case ? Tahnks
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A subclass cannot access private members of the superclass. If a subclass of the outer class is also an inner class of the outer class it can access the private members of the superclass, something it cannot normally do if it were just a subclass.
[ July 26, 2006: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure whether my last post is relevant to your question but I'll leave it anyway.

In the second case the inner class is an outer class, whereas in the first example there is no parent-child relationship. So in the second case you can use the benefits (or curses) of polylmorphism and co., but in the first case you cannot.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rather than advantage, I would say one of the feature in the latter case is innerclass object can be referenced by superclass reference.
 
munna next
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand the concept. Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic