Access levels
Modifier |
Class |
| Package
Subclass |
| World
Public |
Y |
Y |
Y |
Y |
Protected |
Y |
Y |
Y |
N |
No modifier |
Y |
Y |
N |
N |
Private |
Y |
N |
N |
N |
The following table shows where the members of the Alpha class is visible for each of the access modifiers that can is AP Plied to them.
Https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
Modifier |
Alpha |
Beta |
alphasub |
Gamma |
Public |
Y |
Y |
Y |
Y |
Protected |
Y |
Y |
Y |
N |
No modifier |
Y |
Y |
N |
N |
Private |
Y |
N |
N |
N |
Turns out I've been doing the opposite.
The visibility of protected is actually greater than the package. I've been wrong about the internship interview.
The essence of Access levels
If you had a field that's private it means no other class can get on it. wrong! If you really want to your can subvert the access control mechanisms in almost any language. Usually the through is via reflection. The rationale is this debuggers and other system tools often need to see private data, so usually the reflection INTERFAC Es allow you to does this.
C + + doesn ' t has this kind of reflection, but there can just use direct memory manipulation since C + + is fundamentally Open memory.
The point of access control isn't to prevent access, but more to signal that the class prefers to keep some things to its Elf. Using access modifiers, like so many things in programming, is primarily about communication.
Http://martinfowler.com/bliki/AccessModifier.html
It is an expert, said the words are too level!
I understand that access control is actually compiled at compile time, something like a macro definition and does not have a runtime check.
I don't know if this understanding is wrong. I haven't found a way to verify this point for the time being. I hope someone can give a concrete statement.
From for notes (Wiz)
Java access levels (access control)