From 9bf0300ee135d9c39f0f8f97ff0250bc2986eb86 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 6 Mar 2020 17:50:02 -0600 Subject: [PATCH] public, protected, private remove old example and use Oracle docs table instead --- study/STUDY.MD | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/study/STUDY.MD b/study/STUDY.MD index 16981a7..4c8cf52 100644 --- a/study/STUDY.MD +++ b/study/STUDY.MD @@ -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: + +![Classes and Packages of the Example Used to Illustrate Access Levels](https://i.imgur.com/30JkIXg.png) + +| 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