interface TestInterface {
void work();
}
class TestClass {
public void work(){
System.out.println("Work in CLASS");
}
}
public class Driver extends TestClass implements TestInterface {
public static void main(String[] args) {
new TestClass().work();
}
}
任何人都可以向我解释一下,为什么仅仅因为 TestClass 中存在相同的工作方法签名,该类就可以正常编译?
最佳答案
实现接口(interface)的要求是该类提供该接口(interface)指定的所有方法的实现。 Driver
类提供了 work()
所需的实现,因为它从 TestClass
继承了完全匹配的方法。所以它可以用作TestInterface
的实现。
关于java - 接口(interface)和类中的方法签名相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26960261/