当前位置:网站首页>[Tang Laoshi] C -- encapsulation: member method
[Tang Laoshi] C -- encapsulation: member method
2022-06-27 18:19:00 【An old lion of Tang Dynasty】
Last article review
Access modifier
Determine access to member variables
public—— public
private—— private
Member variables
Variables declared in class
Describe the characteristics
The assignment is arbitrary
Any type
Any number
Today we will study in the future
Behavior of objects
Member method
【 Member method 】
Through the previous articles , We can already use member variables to describe the characteristics of objects in classes , But for objects , Characteristics alone are not enough . Such as human characteristics : full name , Age , Gender , Nationality and so on can be expressed by member variables , But for human behavior : Walk , having dinner , Sleep and so on , You can't use member variables . What we are going to learn today Member method , In the idea of object-oriented programming , Namely Used to express behavior Of !
Member method ( function )
↓↓↓↓
Declare methods in classes ( function )
↓↓↓↓
Write in a class statement block

Member method ( function ) The basic rules of
1. Declared in a class statement block
2. The rules are basically the same as the function declaration rules
3. Affected by access modifier rules
4. Is used to describe the behavior of objects
5. The return value parameter is not restricted
6. There is no limit to the number of methods
Member method ( function ), It is used to represent the behavior of objects , We can command an object to do a certain behavior through member methods , Concrete behavior is implemented externally without concern . We just need to know that we can get a certain result by issuing an order .
For example, when we play games , Player objects can move , Can release skills , These are the actions of the player object , We just need to call the corresponding behavior method ( function ), It can act accordingly . We only need to implement the specific logic in the function .
How to use these member methods ( function )?
↓↓↓↓

Be careful
The member method should not add static keyword
The member method must instantiate the object before using
Member methods are affected by access modifiers
public Decorated methods can be called externally
private Decorated methods can only be called internally
Don't write access modifiers to think private
【 summary 】
The member method is simple to understand : Write methods in classes ( function ), These methods represent the behavior of the object , These behaviors are realized through the logic in the method .
Member method
Describe behavior
Class
Any number
Return values and parameters
According to the demand
Focus on Tang Laoshi Get more dry content

边栏推荐
- leetcode 142. Circular linked list II
- Why should string be designed to be immutable?
- 印象深刻的问题
- 2/14 preliminary calculation geometry
- How to modify / display GPIO status through ADB shell
- Handling of difficult and miscellaneous problems during the installation and configuration of qt5.5.1 desktop version (configuring arm compilation Kit)
- Software testing Basics - software testing history, process, classification, benefits, limitations
- 电子智慧套装教程
- Dark horse programmer - software testing foundation class -02-30-45 tools open browser running code, audio, video, test points, audio and video labels, layout labels. Advanced hyperlink syntax, absolu
- Simulated process scheduling
猜你喜欢

The power of code refactoring: how to measure the success of refactoring

Shardingsphere & Atlas & MYCAT comparison

Drawing for example study of flashcc

Explain the distributed computing of Apache skywalking OAP in detail

On array-_-
![[qt learning notes]qt uses MFC compilation to generate DLL libraries. The problem that DLL cannot be loaded occurs on computers without programming environment](/img/fb/4cf7013687973a7214e51faf3358c0.jpg)
[qt learning notes]qt uses MFC compilation to generate DLL libraries. The problem that DLL cannot be loaded occurs on computers without programming environment

软件测试基础-软件测试历史流程,分类,好处,限制
A large number of missing anchor text

软件测试学习-黑马程序员,软件测试学习大纲

leetcode 19. Delete the penultimate node of the linked list
随机推荐
Deeply digitise, lead cloud nativity and serve more developers
P. Simple application of a.r.a method in Siyuan (friendly testing)
Wanzhou gold industry: what are the differences between gold t+d investment and other investments?
Use lamda expression and stream flow to traverse map and list
Oracle概念二
Ping An technology's practice of migrating from Oracle to ubisql
Determine the maximum number of specific words in a string
2022 Liaoning latest fire facility operator simulation test question bank and answers
Asemi rectifier bridge kbp210 parameters, kbp210 specifications, kbp210 dimensions
Application practice of day13 for loop distinguish the application of traversing break continue
当发布/订阅模式遇上.NET
Advanced learning of MySQL -- Application -- view, stored procedure, trigger
新产品新人事新服务,英菲尼迪继续深耕中国未来可期!
leetcode 92. Reverse linked list II
leetcode 69. Square root of X
LACP details
全面解析零知识证明:消解扩容难题 重新定义「隐私安全」
简历如何去写?
(POJ - 1847) tram (shortest circuit)
Halcon: discrete digital OCR recognition