当前位置:网站首页>[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
边栏推荐
- Print linked list from end to end
- FAQs for datawhale learning!
- Phpstudy set LAN access
- How to improve data security by renting servers in Hong Kong
- Pat grade B 1009 is ironic (20 points)
- Find a line in a file and remove it
- Geek Daily: the system of monitoring employees' turnover intention has been deeply convinced off the shelves; The meta universe app of wechat and QQ was actively removed from the shelves; IntelliJ pla
- [Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University
- Recommendation of books related to strong foundation program mathematics
- Line segment tree blue book explanation + classic example acwing 1275 Maximum number
猜你喜欢
Gym welcomes the first complete environmental document, which makes it easier to get started with intensive learning!
Point cloud data denoising
Detailed and not wordy. Share the win10 tutorial of computer reinstallation system
Battle drag method 1: moderately optimistic, build self-confidence (1)
2.1 use of variables
Nerfplusplus parameter format sorting
2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
In 2021, the global revenue of syphilis rapid detection kits was about US $608.1 million, and it is expected to reach US $712.9 million in 2028
1.5 learn to find mistakes first
Camera calibration (I): robot hand eye calibration
随机推荐
Thread, thread stack, method stack, the difference of creating thread
Basic knowledge of dictionaries and collections
In 2021, the global revenue of thick film resistors was about $1537.3 million, and it is expected to reach $2118.7 million in 2028
Explore the internal mechanism of modern browsers (I) (original translation)
Wargames study notes -- Leviathan
Basic command of IP address configuration ---ip V4
How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
Detailed and not wordy. Share the win10 tutorial of computer reinstallation system
2022 Xinjiang latest construction eight members (standard members) simulated examination questions and answers
MySQL dump - exclude some table data - MySQL dump - exclude some table data
P5.js development - setting
Machine learning support vector machine SVM
Battle drag method 1: moderately optimistic, build self-confidence (1)
How to set the system volume programmatically- How to programmatically set the system volume?
How to modify the network IP addresses of mobile phones and computers?
Test panghu was teaching you how to use the technical code to flirt with girls online on Valentine's Day 520
Rad+xray vulnerability scanning tool
Global and Chinese market of charity software 2022-2028: Research Report on technology, participants, trends, market size and share
Bool blind note - score query
Microservice framework - frequently asked questions