Home > Java > javaTutorial > How to implement static and dynamic binding in java

How to implement static and dynamic binding in java

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-06-03 18:22:03
forward
1109 people have browsed it

Comparison of different bindings

1. Static binding occurs during compilation, and dynamic binding occurs during runtime.

2. Dynamic binding is more flexible than static binding, because static binding is determined during the compilation process, while dynamic binding does not know which method to call during the compilation process.

3. Static binding calls methods faster than dynamic binding, because static binding can be called directly, while dynamic binding needs to search the method table.

Example

Static binding

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()
 
}
 
}
Copy after login

(2)Dynamic binding

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()
 
}
 
}
Copy after login

The above is the detailed content of How to implement static and dynamic binding in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template