Home  >  Article  >  Java  >  What does polymorphism mean in java?

What does polymorphism mean in java?

青灯夜游
青灯夜游Original
2019-05-17 17:09:469091browse

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!

Statement:
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
Previous article:What is swing in javaNext article:What is swing in java