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
热门推荐
10 虎年台词祝福语大全简短
11 生日果酒祝福语简短独特
12 婆婆生娃祝福语简短
13 高温祝福语短语大全简短
14 送女士祝福语长辈简短
15 结婚对白誓言简短祝福语
16 六十岁大寿祝福语简短
17 新年的鸡汤祝福语简短
18 同事男生节祝福语简短