


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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment