当前位置:网站首页>Access rights - private, public, protected
Access rights - private, public, protected
2022-07-26 11:04:00 【Baby paper d】
Instance methods in a class can always operate instance variables and class variables in that class , Class methods can always operate on class variables in this class , This has nothing to do with access restrictions .
One :private—— Private variables and private methods
Private variables and private methods Only valid in the current class , If an object of this class is created in another class , Then the object cannot access its own private variables and call private methods .
Two :public—— Common variables and common methods
Create an object of another class in one class , This object can manipulate common variables and common methods in its class .
3、 ... and :protected—— Protected member variables and methods
When using a class in another class Andy After creating an object , If this class and class Andy In the same package , Then the object can access protected Variables and protected Method .
Four : Friendly variables and friendly methods
When using a class in another class Andy After creating an object , If this class and class Andy In the same package , Then the object can access friendly variables and friendly methods in its own class .
If you use import Statement introduces another class in the package , And create an object with this class , Then the object of this class cannot access its own friendly variables and friendly methods .
ps:
Out-of-service protected and private decorator .
Access restriction modifiers are arranged in order of access rights from high to low :public、protected、 Amicable 、private.
边栏推荐
- 公司项目中的biz层和manager层是干啥的
- Pytest execution rules_ Basic usage_ Common plug-ins_ Common assertions_ Common parameters
- ThreadPoolExecutor是怎样执行任务的
- Pengge C language - minesweeping 2021-08-16
- Bash shell学习笔记(五)
- Pytest fixture decorator
- List ascending and descending
- SCADA和三大工业控制系统PLC、DCS、FCS
- Bash shell学习笔记(二)
- logging 学习最终版-配置的不同级别日志打印的颜色
猜你喜欢
随机推荐
为什么需要自动化测试?软件测试师带你测评不同软件测试工具
List and dictionary instance applications (※)
Definition and use of C language namespace
344. Reverse string
Many people don't know whether they are looking for Kanban software or Kanban software
Pengge C language - minesweeping 2021-08-16
Logging learning final edition - configured different levels of log printing colors
27. Remove elements
Sword finger offer (44): flip the word order sequence
数据可视化-《白蛇2:青蛇劫起》(2)
242. Effective letter heteronyms
BigDecimal's addition, subtraction, multiplication and division, size comparison, rounding up and down, and BigDecimal's set accumulation, judge whether BigDecimal has decimal
Notes on intellectual property law in Yu classroom
Minesweeping Pro version 2021-08-19
Visual conversion of nmap vulnerability scanning results
Summary of the seventh class of pengge C language
WinPcap packet capturing function pcap_ Loop (), stop the problem
@Notblank, @notnull, @notempty differences and uses
Scrapy ip代理无响应
Basic use of logging








