Home > Java > JavaBase > body text

What is the implementation mechanism of java polymorphism?

王林
Release: 2020-05-16 11:04:04
Original
4154 people have browsed it

What is the implementation mechanism of java polymorphism?

The implementation mechanism of Java polymorphism:

The implementation mechanism of Java polymorphism is that reference variables defined by the parent class or interface can point to subclasses Or an instance object of an implementation class, and the method called by the program is dynamically bound during runtime. It refers to the method of the specific implementation object pointed to by the variable, that is, the method of the object running in the memory, rather than the type of the reference variable. method defined in.

(Video tutorial recommendation: java video)

Essence:

1. Compile-time polymorphism (also known as static Polymorphism)

2. Run-time polymorphism (also known as dynamic polymorphism)

1. Compile-time 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.

2. Runtime polymorphism

There are usually two implementation methods:

1. Subclass inherits parent class (extends)

2. Class implementation interface (implements)

No matter which method is used, the core lies in the rewriting of the parent class method or the implementation of the interface method to obtain different executions at runtime. Effect.

Recommended tutorial: Getting started with java development

The above is the detailed content of What is the implementation mechanism of java polymorphism?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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