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()
B 类
,它是针对旧版本的接口
进行编译的。 - Uwe Plonusg()
,这会导致编译错误。很可能当你执行你的类时,它会执行最后一个成功编译的版本。 - user902383