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:

Inheritance and protected inner classes - complete posting

Posted by Christian Schmitt on December 07, 2000 at 8:10 AM

Sorry, i accidently hit the Post button as i was still composing my question...

Again i've got a class A and a protected inner class B with a protected constructor:

public class A{
...
protected class B{
protected B (String s, boolean b){
...
}
...
}
}

And i've got a class C that inherits form A. In C there's a method which should create some Objects of B. The following code only compiles if B is declared public:

public class C extends A{
...
public void f(String s, boolean b){
B b = new B(s,b);
...
}
}

If B is still protected, the compiler complains about a missing constructor of B with signature (C, String, boolean). I know that's something about the 'secret' reference to A (or C??) which has to be passed to the constructor of B. But why does it work with B declared public? And i don't want to declare B public, so how can i do this with a protected B?

I've tried the following:
- I provided a constructor with signature (A, String, boolean) - not C but A, because there will be a D and an E ... which inherit from A. Now the compiler complains about a missing constructor with signature (C,A,String, boolean).
- I made a method in A which is called by a method in C and generates and returns a B. That works. But i don't want to do this.

Thanks for your help,
Chris





Replies:

Sponsored Links



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