"Peter Kirk" <peter_kirk@PLEASE_DONT_SPAM_ME_ANYMORE_alpha-gruppen.NO_MORE_dk_ARGGGGH> wrote in message news:<3f8f9b23$0$54835$. dk>...
> "lonelyplanet999" <> wrote in message
> news: om...
> > Yes, I missed the package statement. I modified the packages as below:
> >
> > c:\javapgm\aclass2\aclass1\Aclass1.java
>
> <snip>
>
> Hmm. I think you seem to be swapping things around a bit each time. You have
> to make sure that the java classes are in the same directory as the pacakage
> statement indicates.
>
> Eg. if I have a directory/file like this (where the source files are stored
> in a tree under the "src" directory):
>
> c:\myproject\src\a\b\c\MyClass.java
If I don't interpret wrongly, I also follow the rule.
The only difference is the classes defined recursively extends another
one, as described below:
c:\myproject\src\Aclass3.java has only one non-abstract class named
Aclass3. This class extends another class Aclass2.
c:\myproject\src\aclass2\Aclass2.java has only one abstract class
named Aclass2. This class extends another class Aclass1.
c:\myproject\src\aclass2\aclass1\Aclass1.java has only one abstract
class named Aclass1. This class doesn't extend any other class.
The first statement inside Aclass1.java is
package aclass1;
The first 2 statements inside Aclass2.java are
package aclass2;
import aclass1.Aclass1;
The first 3 statements inside Aclass3.java are
package aclass3;
import aclass2.Aclass2;
import aclass2.aclass1.Aclass1;
Compilation of Aclass1.java & Aclass2.java succeeded but that of
Aclass3.java failed. Even if I commented statement 'import
aclass2.aclass1.Aclass1;', compilation still failed.
What I don't understand is what java rule I have violated that caused
the compilation failure.
>
> then the package statement in MyClass.java should look like this:
>
> package a.b.c;
>
> Likewise, if I have this file:
>
> c:\myproject\src\d\e\f\MyOtherClass.java
>
> then the package statement in MyOtherClass.java should look like this:
>
> package d.e.f;
>
> Then, if MyOtherClass should extend MyClass (or just use it in some way),
> then I need an import statement in MyOtherClass, like this:
>
> import a.b.c.MyClass;
>
>
> Hope you can make some sense of that, and get your classes to compile.
>
> Peter
|