Java中的静态绑定和动态绑定之间有什么区别?
以下是静态绑定和动态绑定之间的显着区别-
静态绑定
它在编译时发生。
它可以通过私有,静态和最终方法进行观察。
它被称为早期绑定。
示例
class Super{
public static void sample(){
System.out.println("This is the method of super class");
}
}
Public class Sub extends Super{
Public static void sample(){
System.out.println("This is the method of sub class");
}
Public static void main(String args[]){
Sub.sample()
}
}输出结果
This is the method of sub class
动态绑定
它在运行时发生。
它是在实例方法中观察到的。
这被称为后期绑定。
示例
class Super{
public void sample(){
System.out.println("This is the method of super class");
}
}
Public class extends Super{
Public static void sample(){
System.out.println("This is the method of sub class");
}
Public static void main(String args[]){
new Sub().sample()
}
}输出结果
This is the method of sub class