当前位置:网站首页>访问权限——private,public,protected
访问权限——private,public,protected
2022-07-26 10:40:00 【孩纸D】
类中的实例方法总是可以操作该类中的实例变量和类变量,类方法总是可以操作该类中的类变量,这与访问限制符没有关系。
一:private——私有变量和私有方法
私有变量和私有方法只在当前类中有效,若在另一个类中创建了该类的一个对象,则该对象是不能访问自己的私有变量和调用私有方法的。
二:public——共有变量和共有方法
在一个类中创建了另一个类的一个对象,该对象是可以操作其类中的共有变量和共有方法。
三:protected——受保护的成员变量和方法
当在另一个类中用类Andy创建了一个对象后,如果这个类与类Andy在同一个包中,那么该对象可以访问自己类中的protected变量和protected方法。
四:友好变量和友好方法
当在另一个类中用类Andy创建了一个对象后,如果这个类与类Andy在同一个包中,那么该对象可以访问自己类中的友好变量和友好方法。
如果使用import语句引入了另外一个包中的类,并用该类创建了一个对象,那么该类的对象不能访问自己的友好变量和友好方法。
ps:
不能用protected和private修饰类。
访问限制修饰符按访问权限从高到低的排列顺序:public、protected、友好的、private。
边栏推荐
- Common classes (understand)
- Mlx90640 infrared thermal imager temperature sensor module development notes (VI) pseudo color coding of infrared images
- Phase 4: one of College Students' vocational skills preparation in advance
- Redis特殊数据类型使用场景
- 英语基础句型结构------起源
- 鹏哥C语言——扫雷2021-08-16
- Error[Pe147]: declaration is incompatible with '错误问题
- 第5期:大学生入职必备技能之二
- .net operation redis hash object
- [leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字
猜你喜欢

The problem of large fluctuation of hx711 data
![Error[Pe147]: declaration is incompatible with '错误问题](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[Pe147]: declaration is incompatible with '错误问题

在神州IV开发板上为STemWin 5.22加入触屏驱动

SAP ABAP 守护进程的实现方式

.NET5WTM(ASP.NET Core) PGSql开箱操作

$router和$route的区别

Problems encountered in QRcode QR code (C language)

Uniapp uses the simple method signalr (only for web debugging, cannot package apps)

【论文下饭】Deep Mining External Imperfect Data for ChestX-ray Disease Screening

Zongzi battle - guess who can win
随机推荐
比较器(Comparable与Comparator接口)
[leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]
Parallelism, concurrency and several directions for high concurrency optimization
控制随机抽中几率 [ C# | Random ]
英语基础句型结构------起源
剑指Offer(五十二):正则化表达式
Datav beautiful data screen production experience
在神州IV开发板上为STemWin 5.22加入触屏驱动
winpcap 抓包函数pcap_loop(),停止问题
Write to esp8266 burning brush firmware
在altium designer中禁用USBJATG
$router和$route的区别
IAR sprintf 浮点 在UCOS 总格式化成0.0的问题
The problem of large fluctuation of hx711 data
扫雷pro版2021-08-19
RT-Thread 学习笔记(六)--- 开启基于SPI Flash的elmfat文件系统(上)
Error[Pe147]: declaration is incompatible with '错误问题
Flutter 防止科学计数并去除尾数无效0
鹏哥C语言20210811程序结构作业
centos8(liunx)部署WTM(ASP.NET 5)使用pgsql