The implementation mechanism of Java polymorphism is that reference variables defined by the parent class or interface can point to instance objects of the subclass or implementation class, and the methods called by the program are dynamically bound at runtime. , refers to the method of the specific implementation object pointed to by the reference variable, that is, the method of the object running in the memory, rather than the method defined in the type of the reference variable.
Essentially, there are two types of polymorphism:
·Compile-time polymorphism (also known as static polymorphism)
·Run-time polymorphism (also known as dynamic polymorphism)
Overload is an example of compile-time polymorphism. Compile-time polymorphism is determined at compile time, and the determined method is called at runtime.
What we usually call polymorphism refers to runtime polymorphism, that is, it is not sure which specific method to call at compile time, and it is delayed until runtime. This is why polymorphic methods are sometimes called deferred methods.
Polymorphism usually has two implementation methods:
## ·Subclass inherits parent class (extends)
·Class implements interfaces (implements)
No matter which method it is, its core lies in the rewriting of the parent class method or the interface Implementation of methods to achieve different execution effects at runtime. To use polymorphism, you should follow one rule when declaring objects: always declare the parent class type or interface type, and create the actual type. PHP Chinese website has a large number of freeJAVA introductory tutorials, everyone is welcome to learn!
The above is the detailed content of What is the polymorphism mechanism of java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment