Three major characteristics of object-oriented: encapsulation, inheritance, polymorphism

王林
Release: 2020-06-09 17:30:52
forward
4316 people have browsed it

Three major characteristics of object-oriented: encapsulation, inheritance, polymorphism

The three major characteristics of object-oriented: encapsulation, inheritance, and polymorphism.

Detailed introduction:

1. Encapsulation

Hide the properties and implementation details of the object, and only provide public access to the outside world.

Benefits: Isolate changes, facilitate use, improve reusability and security.

Principle: Hide content that does not need to be provided externally; hide attributes and provide public methods to access them.

(Recommended video tutorial:java video tutorial)

2. Inheritance

Improve code reusability. Inheritance is a prerequisite for polymorphism.

Note:

1. All constructors in the subclass will access the constructor with empty parameters in the parent class by default. By default, there is super() in the first line; if there is no empty parameter constructor Function needs to be specified in the subclass;

2. In the constructor of the subclass, you can use this to specify other constructors of your own.

3. Polymorphism

is a reference variable defined by a parent class or interface that can point to an instance object of a subclass or a specific implementation class.

Benefits: Improves the scalability of the program.

Disadvantages: When the parent class reference points to the subclass object, although the scalability is improved, only the methods in the parent class can be accessed, and the methods in the subclass cannot be accessed, which is the limitation of access.

Prerequisite: Implementation or inheritance relationship; override parent class method.

Recommended tutorial:java entry program

The above is the detailed content of Three major characteristics of object-oriented: encapsulation, inheritance, polymorphism. 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!