我对动态绑定和静态绑定感到困惑.我已经读过在编译时确定对象的类型称为静态绑定,在运行时确定它称为动态绑定.
以下代码中会发生什么:
静态绑定还是动态绑定?
这显示了什么样的多态性?
class Animal
{
void eat()
{
System.out.println("Animal is eating");
}
}
class Dog extends Animal
{
void eat()
{
System.out.println("Dog is eating");
}
}
public static void main(String args[])
{
Animal a=new Animal();
a.eat();
}
Run Code Online (Sandbox Code Playgroud)