当相同的方法在in 中可用时,我如何调用class B
from的方法?在中。Package.one
class B
Package.two
main()
class RunAB
Package.two
Package
|-----one
| |---A.java (interface)
| |---B.java (implements A)
|-----two
|---B.java (implements A)
|---RunAB.java
//Package.one 目录
package Package.one;
public interface A {
int area();
}
.
package Package.one;
public class B implements A {
public int width;
public int height;
public int area() {
System.out.println("i am form one");
return width*height;
}
public B(int a, int b) {
width = a;
height = b;
}
}
//package.two 目录
package Package.two;
import Package.one.*;
class B implements A {
public int width;
public int height;
public int area() {
System.out.println("i am form two");
return width*height;
}
public B(int a, int b) {
width = a;
height = b;
}
}
.
package Package.two;
import Package.one.*;
class RunAB {
public static void main(String args[]) {
B b = new B(10,12);
System.out.println("area is " + b.area());
}
}
///输出 ;
i am form two
area is 120
Java 怎么知道它需要从包二而不是包一中调用方法?interface A
在这个调用过程(决策)中是否有任何作用?