Home  >  Article  >  What is a class?

What is a class?

烟雨青岚
烟雨青岚Original
2020-06-13 16:13:4514433browse

What is a class?

What is a class?

Definition:

Class (Class) is the basis for information encapsulation in object-oriented programming (OOP, Object-Oriented Programming). A class is a user-defined reference data type, also called a class type. Each class contains a data description and a set of functions that manipulate data or pass messages. Instances of a class are called objects.

Three major characteristics of classes:

1. Encapsulation

Encapsulates data and operations into an organic whole. Because classes The private members are hidden and only provide limited interfaces to the outside, so it can ensure high internal cohesion and low coupling with the outside. Users do not need to know the specific implementation details, but only need to use the members of the class with specific access rights through the external interface, which can enhance security and simplify programming.

2. Inheritance

Inheritance is more in line with cognitive rules, making the program easier to understand while saving unnecessary repeated code.

3. Polymorphism

The same operation acts on different objects and can have different interpretations and produce different execution results. At runtime, methods in the implemented subclass (derived class) can be called through a pointer to the parent class (base class).

Define a class:

    class类名
{
 
public:
公有成员
private:
私有成员
 
protected:
保护成员
};

For more related knowledge, please visit PHP Chinese website! !

The above is the detailed content of What is a class?. 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