本篇内容主要讲解“java静态和动态绑定怎么实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“java静态和动态绑定怎么实现”吧!
不同绑定的比较
1、静态绑定发生在编译期,动态绑定发生在运行期。
2、动态绑定的灵活性高于静态绑定,因为静态绑定是在编译过程中确定的,动态绑定在编译过程中不知道调用哪种方法。
3、静态绑定调用方法比动态绑定快,因为静态绑定可以直接调用,动态绑定需要搜索方法表。
实例
静态绑定
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()
}
}
(2)动态绑定
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()
}
}
到此,相信大家对“java静态和动态绑定怎么实现”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!