当前位置:网站首页>[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

边栏推荐
- Global and Chinese market of cyanuric acid 2022-2028: Research Report on technology, participants, trends, market size and share
- 【leetcode】1027. Longest arithmetic sequence (dynamic programming)
- Micro service knowledge sorting - three pieces of micro Service Technology
- First knowledge of database
- Global and Chinese market of high temperature Silver sintering paste 2022-2028: Research Report on technology, participants, trends, market size and share
- [postgresql]postgresql custom function returns an instance of table type
- AcWing 1460. Where am i?
- 2.5 conversion of different data types (2)
- [raid] [simple DP] mine excavation
- Get log4net log file in C - get log4net log file in C
猜你喜欢

2.4 conversion of different data types

thrift go

Detailed and not wordy. Share the win10 tutorial of computer reinstallation system

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%

2.3 other data types

JMeter connection database

Qtablewidget control of QT

2022 Xinjiang latest road transportation safety officer simulation examination questions and answers

MDM mass data synchronization test verification

你真的知道自己多大了吗?
随机推荐
Global and Chinese market of two in one notebook computers 2022-2028: Research Report on technology, participants, trends, market size and share
Promethus
AI enhanced safety monitoring project [with detailed code]
Commands related to files and directories
Q&A:Transformer, Bert, ELMO, GPT, VIT
Introduction to golang garbage collection
Day6 merge two ordered arrays
【leetcode】1027. Longest arithmetic sequence (dynamic programming)
Fingerprint password lock based on Hal Library
Battle drag method 1: moderately optimistic, build self-confidence (1)
About unregistered transfer login page
How to read the source code [debug and observe the source code]
Use of aggregate functions
FPGA 学习笔记:Vivado 2019.1 工程创建
47. Process lock & process pool & Collaboration
6006. Take out the minimum number of magic beans
Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation
Producer consumer mode (multithreading, use of shared resources)
The 15 year old interviewer will teach you four unique skills that you must pass the interview
Acquisition and transmission of parameters in automatic testing of JMeter interface