[Java] What got caught in encapsulation

Access control for 4 members

name Operations during the program Scope of permission for access
private private Only my own class
pakckage private (Write nothing) Classes that belong to the same package as you
protected protected Child classes that belong to the same package as you or inherit from you
public public All Classes

Getter, setter standard

Check access to fields

Let's check the validity of the value in the setter method. (Relevant processing) public void setVariable(String name){ if (name.length() <= 1){ throw new IllegalArgumentException("The name is too short."); } }

Recommended Posts

[Java] What got caught in encapsulation
What is Java Encapsulation?
java (encapsulation)
[Java] Encapsulation
What is a class in Java language (3 /?)
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
What is the main method in Java?
What I got into @Transactional in Spring
What Java programmers find useful in Kotlin
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
What is Java <>?
What is Java
Pi in Java
FizzBuzz in Java
What I learned in Java (Part 2) What are variables?
What I've always been interested in in Java final
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
What I learned in Java (Part 3) Instruction execution statement
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
What I learned when building a server in Java
What is Java technology?
Express failure in Java
What is Java API-java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
[Java] What is flatMap?
Java encapsulation private public
Use PreparedStatement in Java
[Java] What is JavaBeans?
[Java] What is ArrayList?
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java