The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

U got it...

Posted by Kishori Sharan on December 13, 2000 at 2:24 PM

Hi Chris
When you create a newB ( ) method in class A then it is valid to create an object of B in class A. When you inherit a class C from A then newB ( ) is inherited. But, when you call newB ( ) in C then at run time JVM has knowledge that you are calling newB ( ) which was inherited which, in fact, exists in A not in C. So while executing the code in herited newB ( ) all the access restrictions of class A is applied ( not for class C ) and that is why your solution worked. You may not be knowing this, but this is the most widely used approach to get an instance of an inner class. Create a method in top level class which returns an instance of inner class and make constructor of inner class private ( This is what you did ) . So, you are correct in your understanding.
Thanx
Kishori



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us