Home > Java > javaTutorial > body text

What does polymorphism mean in java?

青灯夜游
Release: 2019-05-23 18:35:33
Original
9085 people have browsed it

What does polymorphism mean in java?

#What does polymorphism mean in java?

Polymorphism is another important feature of object-oriented programming. It means that after the properties and methods defined in the parent class are inherited by the subclass, they can have different data types or show different behavior. Behavior, which makes the same property or method have different meanings in the parent class and its various subclasses.

For object-oriented, polymorphism is divided into compile-time polymorphism and run-time polymorphism. Compile-time polymorphism is static and mainly refers to method overloading. It distinguishes different methods based on different parameter lists. After compilation, it will become two different methods, and there is no polymorphism at runtime. Runtime polymorphism is dynamic and is implemented through dynamic binding, which is what everyone usually calls polymorphism.

What are the advantages of java polymorphism?

Java has many advantages. First of all, it has many interfaces, has a certain degree of flexibility and simplification, and can eliminate the coupling relationship between types. It is replaceable and has good program scalability.

How does Java implement polymorphism?

There are three necessary conditions for Java to achieve polymorphism: inheritance, overwriting and upward transformation. Only when these three conditions are met, developers can use unified logic implementation code to process different objects in the same inheritance structure, thereby performing different behaviors.

● Inheritance: In polymorphism, there must be subclasses and parent classes with inheritance relationships.

● Rewriting: The subclass redefines certain methods in the parent class, and when these methods are called, the methods of the subclass will be called.

● Upward transformation: In polymorphism, the reference of the subclass needs to be assigned to the parent class object. Only in this way can the reference call the methods of the parent class and the subclass.

The above is the detailed content of What does polymorphism mean in java?. 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