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

王林
Release: 2020-08-10 16:40:20
forward
4297 people have browsed it

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 myList=new LinkedList<>();
Copy after login

(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!

source:csdn.net
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!