4 java
我知道在动态绑定的情况下,只能调用当前类中存在的那些方法.如果子覆盖父方法,则执行子方法,否则将执行parent方法...
但是在接口的情况下发生了什么,我不知道......这是我的意思的一个例子:
interface TestInterface {
public void show();
}
class Test implements TestInterface {
public void show() {
System.out.println("Hello in show");
}
public String toString() {
System.out.println("Hello in To String");
return "";
}
public static void main(String[] args) {
TestInterface obj = new Test();
obj.show();
obj.toString(); // why it run vilate dynamic binding rule..
}
}
Run Code Online (Sandbox Code Playgroud)