Access modifier [Java]

Access modifier

Access modifiers are added when declaring a class or its members to specify where they can be accessed.

There are four types of access modifiers: "public", "protected", "none", and "private". This time, the accessibility of each access modifier is summarized in the table.

Access modifiers and accessibility

Own class Same package Subclass Other packages
public
protected ×
None × ×
private × × ×

Let's take a look at the table using the protected modifier as an example.

"If it has the protected modifier, it can be accessed from within the same package as your class and from subclasses, but not from other packages."

is what it means.

At the end

Personally, "protected" and "none", "same package" and "subclass" are confusing. I think this is because I don't have a clear understanding of when protected and packages are useful, so I will study.

Recommended Posts

Access modifier [Java]
java final modifier
[Java Silver] Summary of access modifier points
Java abstract modifier [Note]
Access API.AI from Java
About Java access modifiers
Java tips --StaticUtility class modifier
Java basic learning content 5 (modifier)
Access modifier summary-JVM language edition (Java / Groovy / Scala / Kotlin)
Java
Java
[Java] I tried access modifier public and unspecified field access [Eclipse]
Access the network interface in Java
Access Teradata from a Java application
JNA (Java Native Access) pattern collection
Easy database access with Java Sql2o
Access modifier summary-Smartphone application development (Java / Kotlin / Objective-C / Swift / C # / F #)
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Relationship between kotlin and java access modifiers
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
JAVA learning history final modifier and static modifier
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
[Java] Inheritance