• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Class

 
Vidya Singh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From
Corey McGlone's Blog The SCJP Tipline

Need further explanation on statement

While each inner class has a reference to its enclosing class, the reverse is not true (at least not implicitly). A single enclosing class can have one, two, three, or even hundreds of inner classes associated with it.
Unless you declare a reference from the enclosing class to its inner class(es), it has no reference to them.

Thanks,

Vidya
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an article on the Sun Developer Network that is very relevant to this question called Do inner classes have direct access to instance variables and methods of the outer class? Have a look at it as I think that it will answer your questions.

/Pete
 
Marcos R Oliveira
Ranch Hand
Posts: 62
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Vidya,

I think the code below has an example of what McGlone was trying to say:



Marcos.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vidya,

See the code below to have idea of following line:

A single enclosing class can have one, two, three, or even hundreds of inner classes associated with it.




[ April 29, 2007: Message edited by: Chandra Bhatt ]
 
Vidya Singh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vidya wrote:
While each inner class has a reference to its enclosing class, the reverse is not true (at least not implicitly). A single enclosing class can have one, two, three, or even hundreds of inner classes associated with it.
Unless you declare a reference from the enclosing class to its inner class(es), it has no reference to them.


Here is an eg.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic