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

How to implement dynamic binding in java

王林
Release: 2023-05-22 09:46:05
forward
1657 people have browsed it

Concept

1. Dynamic binding refers to binding according to the type of object during operation.

2. The process by which the JVM determines which object to call during running is called dynamic binding.

The process of dynamic binding

3. The virtual machine extracts the method table of the actual type of the object, searches for the method signature, and calls the method.

Example

public class Main {
    public static void main(String[] args){
        A b = new B();
        b.print();
    }
}
 
class A{
    public void print(){
        System.out.println("A");
    }
}
 
class B extends A{
    @Override
    public void print(){
        System.out.println("B");
    }
}
Copy after login

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

Related labels:
source:yisu.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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template