search
HomeJavajavaTutorialThe difference between static binding and dynamic binding in Java

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.

##Dynamic binding uses objects to resolve the binding3ExampleOverload It is an example of static bindingMethod overriding is an example of dynamic binding4.Method typePrivate, final Use static binding for static methods and variablesUse dynamic binding for virtual methodsStatic and dynamic binding examples
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();
   }
}
Old gentleman. no.

Key

Static binding

Dynamic binding

##1 p>

##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!

Statement
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools