java静态和动态绑定怎么实现
作者:小确幸
时间:2023-05-03
浏览:1
不同绑定的比较1、静态绑定发生在编译期,动态绑定发生在运行期。2、动态绑定的灵活性高于静态绑定,因为静态绑定是在编译过程中确定的,动态绑定在编译过程中不知道调用哪种方法。3、静态绑定调用方法比动态绑定快,因为静态绑定可以直接调用,动态绑定需要搜索方法表。实例静态绑定classSuper{publicstaticvoidsample(){System.out.println("Thisisthemethodofsuperclass");}}PublicclassSubextendsSuper{Publics
本文目录
不同绑定的比较
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()
}
}
作者最新文章
xshell连接服务器怎么连 SSH远程登录步骤
2026-11-03 10:13
立刻MV如何删除不需要的MV项目工程
2026-11-02 23:37
beyond compare怎么自动换行
2026-10-23 10:35
Luminar Neo画笔与蒙版使用指南:精准选区与图层合成技巧
2026-10-22 15:23
Photoshop快捷键表格在哪找
2026-10-22 14:42
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































