【发布时间】:2013-08-05 20:40:43
【问题描述】:
interface A
{
public void f();
public void g();
}
class B implements A
{
public void f()
{
System.out.println("B.f()");
}
}
public class Main
{
public static void main(String[] args)
{
B tmp = new B();
tmp.f();
System.out.println("B.f()");
}
}
我没有在B中实现接口A中的所有方法 它有一个错误
The type B must implement the inherited abstract method A.g()
但为什么它可以得到输出
B.f()
B.f()
【问题讨论】:
-
这是不可能的。我假设你的类路径中有一个旧的
class B,它是针对旧版本的interface编译的。 -
@UwePlonus 它只是在项目中使用一个文件进行的测试。
-
你没有实现导致编译错误的方法
g(),并且很可能在你执行你的类时,它正在执行最后一个成功编译的版本
标签: java eclipse methods interface