[3787] in java-interest
Re: Protected Is Default?
daemon@ATHENA.MIT.EDU (Jim Graham)
Mon Nov 27 23:59:23 1995
Date: Mon, 27 Nov 1995 18:20:35 -0800
From: flar@bendenweyr.Eng.Sun.COM (Jim Graham)
To: java-interest@java.Eng.Sun.COM, David.Geary@Central.Sun.COM
> I've got a class that extends Container:
>
> package foo;
>
> import java.awt.Container;
>
> class A extends Container {
> B b = null;
> }
>
> When I compile:
>
> trilby >> javac foo/A.java
> foo/A.java:5: No constructor matching Container() found in class java.awt.Container.
> class A extends Container {
> ^
> 1 error
Since you didn't make a constructor for class A, a default constructor
was added:
A() {
super();
}
Since super() maps to Container.Container() and since the default access
mode is friendly (not protected), that constructor was not visible to you
outside of the java.awt package and so the class definition failed.
If you read the doc comment on Container's constructor you will see that
Containers were not meant to be subclassed outside of java.awt. Try
subclassing one of the other types of Containers, such as Panel, Window,
Dialog, FileDialog or Frame.
...jim
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com