On Fri, 28 Aug 1998 15:13:20 +0000, Steve Cohen wrote:

>I realize this may not be the appropriate place for this question but why can't
>I do this?
>
>//file a:
>
>import java.awt.*;
>public class a {
>    void paint (Graphics g) {
>        ...
>    }
>
>}
>
>//file b:
>import java.awt.*;
>import a;
>
>public class b {
>    public a A;
>    ...
>    void paint (Graphics g) {
>        A.paint(g);
>    }
>}
>
>The compilation of file b fails with an error message about an unknown method
>paint( java.awt.Graphics )
>
>WHY?  This code compiles fine if it is all in one file

Well, the problem is that your paint method is not public and you
do an "import" of a.  If you don't do the import but a is part of
the same "package" as b, this will work just fine since they tne
package-private paint() method will work.  Import is defined to
import packages that are *not your own* and thus by doing that
import, you define that in class a you can only access public methods.

When it is all in the same file it works just fine since you have
access to package methods (methods without the public modifier)

Note that normally one does not import classes that are within your
own package.  Your code looks like both classes are in no package
(as in the outside package) and thus within the same package as
eachother.

Michael Sinz -- Director of Research & Development, NextBus Inc.
mailto:[EMAIL PROTECTED] --------- http://www.nextbus.com
My place on the web ---> http://www.users.fast.net/~michael_sinz

Reply via email to