经过2-3个小时才知道,编译时和运行时间之间有什么区别。最后,我想出了这个。编译时间vs运行时间
在运行时分配的内存涉及运行时/动态绑定,并在编译时分配,涉及编译时/静态绑定。
,然后我试过了这个例子
class myclass {
void here() {
System.out.println("Here from myclass !!");
}
void here(int i) {
System.out.println("Here !!" + i);
}
}
class thisclass extends myclass {
void here() {
System.out.println("Here from thisclass !!");
}
}
public class poly {
public static void main(String s[]) {
myclass m= new myclass();
myclass a= new thisclass();
m.here();
m.here(12);
a.here();
a.here(13);
}
}
所以,我也发现,myclass a= new thisclass();
被认为是运行时绑定。由于,a
是myclass
的对象,但突然编译器发现,类错误匹配。所以,它会动态绑定thisclass
对象的空间。
所以,直到这里,我得到了东西。但是,我发现,另一个常见的答案是重载指编译时间和覆盖参考运行时间。我没有明白这一点。
thisclass a= new thisclass();
a.here();
这是否也称为运行时绑定。 ??如果在这里写错了,请纠正我。
是C++代码吗? – Mob
随意添加[tag:C#]或[tag:Java]。这不是C++。 –
对不起。这是java代码 – Ravi