Home > Java > Javagetting Started > body text

What is java polymorphism

(*-*)浩
Release: 2019-11-11 11:39:54
Original
2635 people have browsed it

What is java polymorphism

Polymorphism is the ability of the same behavior to have multiple different manifestations or forms.

Polymorphism is the same interface, using different instances to perform different operations, as shown in the figure: (Recommended learning: java course)

What is java polymorphism

#Polymorphism is the embodiment of multiple expressions of objects.

In reality, for example, when we press the F1 key:

如果当前在 Flash 界面下弹出的就是 AS 3 的帮助文档;
如果当前在 Word 下弹出的就是 Word 帮助;
在 Windows 下弹出的就是 Windows 帮助和支持。
同一个事件发生在不同的对象上会产生不同的结果。
Copy after login

Advantages of polymorphism

Eliminate the coupling relationship between types

Replaceability

Extensibility

Interface

Flexibility

Simplification

Three necessary conditions for the existence of polymorphism

Inheritance

Rewriting

The parent class reference points to the child class object

For example:

Parent p = new Child();
Copy after login

When calling a method using polymorphism, first check whether the method exists in the parent class. If not, a compilation error will occur; if so, call it again. Method with the same name of the subclass.

Benefits of polymorphism: It allows the program to be well expanded and can handle objects of all classes universally.

The above is the detailed content of What is 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