而要调用以及修改 则类要多加两个函数 get调用获取 和set 修改
时间: 2024-06-07 22:10:51 浏览: 90
是的,如果想要对类中的私有变量进行修改或获取,需要在类中增加对应的get和set函数。get函数用于获取私有变量的值,set函数用于设置私有变量的值。通常情况下,get和set函数的命名规则都是在变量名前面加上get或set,例如:如果私有变量名为“age”,则get函数的命名为“getAge”,set函数的命名为“setAge”。在这些函数中,我们可以根据需要对变量进行一些约束或逻辑处理,从而保证变量的正确性。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)