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();
}
}
Can any one explain to me, why just because the same work method signature exists in TestClass this class compiles fine?
The requirement of implementing an interface is that the class provides implementations of all the methods specified by the interface. Class
Driver
provides the required implementation ofwork()
, because it inherits an exactly matching method fromTestClass
. So it can be used as an implementation ofTestInterface
.