当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
Shell script fails to execute repeatedly automatically
easyui03
Sword finger offer (53): a string representing a numeric value
349. Intersection of two arrays
Minesweeping Pro version 2021-08-19
Dictionary and int matrix
Connection between PLC and servo motor
Capture ZABBIX performance monitoring chart with selenium
WinPcap packet capturing function pcap_ Loop (), stop the problem
pytest fixture装饰器
There is an unhandled exception at 0x003b66c3 in MFC: 0xc000041d: unhandled exception encountered during user callback
ISO 639:1988 : Code for the representation of names of languages
Newbie sees the source code arraydeque
Simple use of MFC multithreading
LinkedList of source code
0x00007ffd977c04a8 (qt5sqld.dll) (in a.exe): 0xc0000005: an access violation occurred when reading position 0x0000000000000010
使用Selenium抓取zabbix性能监控图
配置文件以rc结尾什么意思
pytest 用例执行顺序
MySQL quicklearn-2021-09-01









