[BAEL-3149] Java 'private' access modifier (#7669)

This commit is contained in:
NickTononi 2019-09-02 16:06:44 +02:00 committed by KevinGilmore
parent 4e926d3f06
commit 149bfc44be
2 changed files with 16 additions and 7 deletions

View File

@ -3,12 +3,12 @@ package com.baeldung.core.modifiers;
public class Employee {
private String privateId;
public String name;
private String name;
private boolean manager;
public Employee(String id, String name) {
changeId(id);
this.name = name;
setPrivateId(id);
setName(name);
}
private Employee(String id, String name, boolean managerAttribute) {
@ -17,7 +17,7 @@ public class Employee {
this.privateId = id + "_ID-MANAGER";
}
public void changeId(String customId) {
public void setPrivateId(String customId) {
if (customId.endsWith("_ID")) {
this.privateId = customId;
} else {
@ -25,7 +25,7 @@ public class Employee {
}
}
public String getId() {
public String getPrivateId() {
return privateId;
}
@ -43,6 +43,15 @@ public class Employee {
this.manager = manager;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static Employee buildManager(String id, String name) {
return new Employee(id, name, true);
}

View File

@ -4,7 +4,7 @@ public class ExampleClass {
public static void main(String[] args) {
Employee employee = new Employee("Bob","ABC123");
employee.changeId("BCD234");
System.out.println(employee.getId());
employee.setPrivateId("BCD234");
System.out.println(employee.getPrivateId());
}
}