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
热门推荐
3 祝福语简短七夕
10 周二祝福语大全简短
11 新婚祝福语大全简短经典
12 牛年新年祝福语大全简短
13 敏字的祝福语简短
14 海鲜送礼祝福语简短大全
15 宝宝生病简短祝福语大全
16 鼓励孩子小考祝福语简短
17 新年送老师简短祝福语
18 分手快乐祝福语简短