[JAVA] About access modifiers

I am a java beginner. This time, I will output about access modifiers.

Q1: What is an access modifier?

・ Determines the accessible range for methods and variables. [Japanese translation] ** access **: Access, approach, entry and exit

Access scope of specific access modifiers (4)

① ** public **: Can be accessed from anywhere

② ** Modifier **: Only in the same package

③ ** private **: Only in the same class

④ ** protected **: Within the same package class or subclass

When to use access modifiers

There is no particular pattern because public and unqualified patterns are free. ** private ** and ** protected ** are unique.

・ Private: Used in places where access from the outside must be absolutely prevented (Places where personal information is acquired, etc.) It can only be accessed from the specified method.

・ Protect: Can only be used for variables or methods

** [Referenced site] ** https://www.sejuku.net/blog/22679

Recommended Posts

About access modifiers
About Java access modifiers
About =
About method.invoke
About Kotlin
About attr_accessor
About Hinemos
Relationship between kotlin and java access modifiers
About inheritance
About params
About Docker
About Rails 6
About form_for
About Spring ③
About enum
About polymorphism
About Optional
About JitPack
About Dockerfile
About encapsulation
About Docker
About JAVA_HOME
About active_hash
About static
About exceptions
About scope
[Maven] About Maven
[Personal memo] I learned a little about modifiers