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 留学生祝福语简短