| 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 |
public field type get field name () { return this. field name; }public void set field name (field type arbitrary variable name) { this. field = arbitrary variable name; }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