Comparative Analysis of examples of static and dynamic binding of java
This article mainly introduces the java static and dynamic binding examples of comparative analysis of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will get something after reading this java static and dynamic binding example comparative analysis article, let's take a look.
Comparison of different bindings
1. Static binding occurs at compile time and dynamic binding occurs at run time.
2. Dynamic binding is more flexible than static binding, because static binding is determined during compilation, and dynamic binding does not know which method to call during compilation.
3. Static binding calls methods faster than dynamic binding, because static binding can be called directly, and 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 ()}}
(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 ()}} this article ends here. Thank you for reading! I believe you all have a certain understanding of the knowledge of "comparative analysis of java static and dynamic binding examples". If you want to learn more knowledge, you are welcome to follow the industry information channel.