Home> Java> javaTutorial> body text

The difference between static binding and dynamic binding in Java

WBOY
Release: 2023-08-27 23:09:08
forward
1346 people have browsed it

The difference between static binding and dynamic binding in Java

#Binding is a mechanism that creates a link between a method call and the actual implementation of the method. According to the concept of polymorphism in Java, objects can have many different forms. The object form can be resolved at compile time and run time. If the link between method invocation and method implementation is resolved at compile time, we call it static binding; if it is resolved at runtime, we call it dynamic binding. Dynamic binding uses objects to resolve bindings, while static binding uses classes and fields' types.

public class FastFood { public void create() { System.out.println("Creating in FastFood class"); } } public class Pizza extends FastFood { public void create() { System.out.println("Creating in Pizza class"); } } public class Main { public static void main(String[] args) { FastFood fastFood= new FastFood(); fastFood.create(); //Dynamic binding FastFood pza= new Pizza(); pza.create(); } }
Copy after login
##Dynamic binding uses objects to resolve the binding 3 Example Overload It is an example of static binding Method overriding is an example of dynamic binding 4. Method type Private, final Use static binding for static methods and variables Use dynamic binding for virtual methods Static and dynamic binding examples
Old gentleman. no.

Key

Static binding

Dynamic binding

##1p>

##Basic

Resolved at compile time

Resolved at runtime

2

Parsing mechanism

Static binding uses the types of classes and fields

td>

The above is the detailed content of The difference between static binding and dynamic binding in Java. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!