|
|
|
|
Access rights to a class property: special cases
The retrieval and assignment processes can be public, private or protected. The access rights of the property correspond to the less restrictive rights of the two processes. Access rights of the property according to the access rights of the processes: | | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Public | Public | Public | Protected | Public | Protected | Protected | Private | Public | Protected | Private |
The properties are accessible on the instances and by inheritance by respecting the standard restrictions of the public, protected and private inheritances. If the access rights allow reading and not writing, the property is considered read-only. If the access rights allow writing and not reading, the property is considered write-only. These cases trigger an error during the compilation but no error is triggered at runtime. The tables below present the possible cases: - Using the class:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Read/Write | Write-only | Write-only | Protected | Read-only | Protected | Protected | Private | Read-only | Protected | Private |
Using a derived class:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Read/Write | Read/Write | Write-only | Protected | Read/Write | Read/Write | Write-only | Private | Read-only | Read-only | Private |
- Using a class with public inheritance:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Read/Write | Write-only | Write-only | Protected | Read-only | Protected | Protected | Private | Read-only | Protected | Private |
- Using a class derived from a class with public inheritance:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Read/Write | Read/Write | Write-only | Protected | Read/Write | Read/Write | Write-only | Private | Read-only | Read-only | Private |
- Using a class with protected inheritance:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Protected inheritance | Protected inheritance | Protected inheritance | Protected | Protected inheritance | Protected inheritance | Protected inheritance | Private | Protected inheritance | Protected inheritance | Protected inheritance |
- Using a class derived from a class with protected inheritance:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Read/Write | Read/Write | Write-only | Protected | Read/Write | Read/Write | Write-only | Private | Read-only | Read-only | Private |
- Using a class with private inheritance:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Private inheritance | Private inheritance | Private inheritance | Protected | Private inheritance | Private inheritance | Private inheritance | Private | Private inheritance | Private inheritance | Private inheritance |
- Using a derived class with private inheritance:
| | | | Assignment process / Retrieval process | Public | Protected | Private | Public | Private inheritance | Private inheritance | Private inheritance | Protected | Private inheritance | Private inheritance | Private inheritance | Private | Private inheritance | Private inheritance | Private inheritance |
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|