Hi,
I create two public class with same name, in different package, but it
gets error when compiled.
package test.one;
public class myclass1 {
public static void main(String[] args) {
System.out.println("myclass1");
}
}
package test.two;
import test.one.myclass1;
public class myclass1 extends test.one.myclass1{
public static void main(String[] args) {
System.out.println("inherit myclass1");
}
}
Error(3,14): class myclass1 clashes with imported class
test.one.myclass1
Is there aniway I can have same class name on the above case ?
Thank you,
xto
Arne Vajhøj - 25 Aug 2006 04:16 GMT
> I create two public class with same name, in different package, but it
> gets error when compiled.
It should work fine.
> package test.one;
> public class myclass1 {
[quoted text clipped - 13 lines]
> Error(3,14): class myclass1 clashes with imported class
> test.one.myclass1
When you do:
import test.one.myclass1;
you make myclass1 mean test.one.myclass1, but
myclass1 could also mean myclass1 in current package
that is test.two.myclass1 !
Drop the import.
Arne
Patricia Shanahan - 25 Aug 2006 04:18 GMT
> Hi,
>
[quoted text clipped - 20 lines]
>
> Is there aniway I can have same class name on the above case ?
The problem is that you are importing test.one.myclass1. Get rid of the
import, and just depend on fully qualifying the name of the other
myclass1, which you are already doing.
Patricia