Suppose I have a directory C:\Java with a subdirectory pkgA. Now I code two
JAVA files Test1.java and Test2.java, the former in C:\Java and the latter in C:\Java\pkgA. The codes are below:
//Test1.java in C:\Java
import pkgA.*;
public class Test1 {
public static void main(
String[] args) {
Test3
test = new Test3();
test.method1();
test.method2();
}
class Test3 extends Test2 {
void method1() {
//some statements
}
}
class Test2 {
}
//Test2.java in C:\Java\pkgA
package pkgA;
public class Test2 {
protected void method2() {
//some statements
}
}
The problem I was describing is "How to inherit a class in some package while another class with the same name of the class is to be inherited is in the directory with the one is to inherit?" (Sorry for mouthful...)
If I get the codes above compile, the complier complains that method2() can't be found. That's because what Test3 inherits is Test2 in C:\Java, not that in C:\Java\pkgA. But since there's a method1() with the default scope (or purview? I don't know what it's excatly called) that can only be invoked using "." in the same package, I can't move it to C:\Java\pkgA.
In fact, I should just give Test2 in C:\Java a different name, but is there some way of solving this problem without changing the name of any class or moviing them?
Any reply would be appreciated.