当前位置:网站首页>[Tang Laoshi] C -- encapsulation: member variables and access modifiers
[Tang Laoshi] C -- encapsulation: member variables and access modifiers
2022-07-03 20:24:00 【Tang laoshiyi】
Last article review
Class is a template for an object
Used to abstract real objects

Object is an instance of a class
Used to represent a real object individual

Class is a custom variable
Instantiate class objects
Is declaring variables
Today we will study in the future
Characteristics of the object
Member variables
【 Member variables 】
Object oriented programming idea , Simply put, it is abstracted with program language ( Describe ) A real object appears . Now we know that classes are used to describe objects , Objects are instantiated from classes . Specific The characteristics and behavior of objects stay Class representation Mainly through : Member variables and member methods Embodied .
Member variables
↓↓↓↓
Declare variables in classes
↓↓↓↓
Write in a class statement block

Basic rules for member variables
1. Declared in a class statement block
2. Whether the assignment is determined according to the requirements
3. It is used to describe the characteristics of objects
4. It can be of any kind
5. There is no limit to the quantity
First of all, I want to emphasize a point , Class is also a variable type , It's just a custom variable type . It and the structure 、 Enumerations are very similar , It is a variable rule that we can name and define ourselves . So, in the above example, in Person Owned by Person Variables are fully allowed ! You need to understand its concept with object-oriented thinking , Just like you are human , You also have to have a human girlfriend ~
How to use these member variables ?
First we must learn the access modifier
↓↓↓↓
【 Access modifier 】
Access modifier
Current decision
Member variables
Member method
Access rights of
keyword
public—— public
private—— private
protected—— Protect

The access modifier is written before the member variable declaration
Determines the access rights of member variables

1. Public member variables , You can point it out
2. Private member variables , Can only be used inside a class
3. Protected member variables , When we inherit
public
Public member variables
Inside and outside the class
at will Access modification
private
Private member variables
Can only Inside the class
at will Access modification
protected
Explain when inheriting
When declaring member variables
Do not write access modifiers
The default is private
【 Use member variables 】


【 summary 】
Access modifier
Determine access to member variables
public—— public
private—— private
Member variables
Describe the characteristics
Class
The assignment is arbitrary
Any type
Any number
Focus on Tang Laoshi Get more dry content

边栏推荐
- 2.4 conversion of different data types
- 4. Data splitting of Flink real-time project
- Day6 merge two ordered arrays
- 2. Template syntax
- Titles can only be retrieved in PHP via curl - header only retrieval in PHP via curl
- The global industrial design revenue in 2021 was about $44360 million, and it is expected to reach $62720 million in 2028. From 2022 to 2028, the CAGR was 5.5%
- Global and Chinese market of speed limiter 2022-2028: Research Report on technology, participants, trends, market size and share
- Node MySQL serialize cannot rollback transactions
- Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation
- Oak-d raspberry pie cloud project [with detailed code]
猜你喜欢

How can the outside world get values when using nodejs to link MySQL
![[effective Objective-C] - block and grand central distribution](/img/09/22b979b97ea13d649b4b904637b79f.jpg)
[effective Objective-C] - block and grand central distribution

FPGA 学习笔记:Vivado 2019.1 工程创建
![Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles](/img/70/6fd00146418e5d481e951d51428990.png)
Cesiumjs 2022 ^ source code interpretation [7] - Analysis of the request and loading process of 3dfiles

Battle drag method 1: moderately optimistic, build self-confidence (1)

Viewing Chinese science and technology from the Winter Olympics (II): when snowmaking breakthrough is in progress

Based on laravel 5.5\5.6\5 X solution to the failure of installing laravel ide helper

FPGA learning notes: vivado 2019.1 project creation

Exercises of function recursion

Point cloud data denoising
随机推荐
1.5 learn to find mistakes first
Global and Chinese market of liquid antifreeze 2022-2028: Research Report on technology, participants, trends, market size and share
Thread, thread stack, method stack, the difference of creating thread
How can the outside world get values when using nodejs to link MySQL
Acquisition and transmission of parameters in automatic testing of JMeter interface
JMeter connection database
Producer consumer mode (multithreading, use of shared resources)
2022 Xinjiang latest construction eight members (standard members) simulated examination questions and answers
FPGA 学习笔记:Vivado 2019.1 工程创建
MySQL learning notes - single table query
Machine learning support vector machine SVM
2.5 conversion of different data types (2)
2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
Based on laravel 5.5\5.6\5 X solution to the failure of installing laravel ide helper
Global and Chinese market of charity software 2022-2028: Research Report on technology, participants, trends, market size and share
Wechat applet quick start (including NPM package use and mobx status management)
How to improve data security by renting servers in Hong Kong
FAQs for datawhale learning!
Global and Chinese markets of lithium chloride 2022-2028: Research Report on technology, participants, trends, market size and share
In 2021, the global foam protection packaging revenue was about $5286.7 million, and it is expected to reach $6615 million in 2028