Home  >  Article  >  Java  >  What are the necessary conditions for the existence of polymorphism and how to implement it?

What are the necessary conditions for the existence of polymorphism and how to implement it?

王林
王林forward
2020-08-10 16:40:204367browse

What are the necessary conditions for the existence of polymorphism and how to implement it?

Three necessary conditions for the existence of polymorphism:

(Recommended tutorial: java introductory tutorial)

1. Inheritance

2. Rewriting

3. The parent class reference points to the subclass object (the parent class reference points to the subclass object)

For example:

Parent p = new Child();
List<Integer> myList=new LinkedList<>();

(Learning video recommendation: java course)

Polymorphic implementation method:

Method 1: Rewriting

Method 2: Interface

Method 3: Abstract classes and abstract methods

The above is the detailed content of What are the necessary conditions for the existence of polymorphism and how to implement it?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete