mirror of
https://github.com/Xevion/contest.git
synced 2025-12-06 01:14:36 -06:00
public, protected, private remove old example and use Oracle docs table instead
This commit is contained in:
@@ -532,14 +532,28 @@ For each character in the array, compare for equality until one does not match.
|
||||
|
||||
`public`, `protected`, `private` and *a lack of a modifier* are the three possible *access modifiers* one can set for *classes, interfaces, variables and methods*.
|
||||
|
||||
- `public`
|
||||
- Anything and everything can access this.
|
||||
- *`(no modifier)`*
|
||||
- A
|
||||
- `protected`
|
||||
- ?
|
||||
- `private`
|
||||
- ?
|
||||
A table provided by the Oracle JavaSE docs looked like this, and can be very helpful in illustrating who can access according to what modifier:
|
||||
|
||||
| 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 |
|
||||
|
||||
Another table based on a more realistic example:
|
||||
|
||||

|
||||
|
||||
| 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 |
|
||||
|
||||
Source: [Controlling Access to Members of a Class](https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html)
|
||||
|
||||
|
||||
#### Privilege Level Never Changes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user