[BAEL-3149] Java 'private' access modifier (#7669)
This commit is contained in:
parent
4e926d3f06
commit
149bfc44be
@ -3,12 +3,12 @@ package com.baeldung.core.modifiers;
|
|||||||
public class Employee {
|
public class Employee {
|
||||||
|
|
||||||
private String privateId;
|
private String privateId;
|
||||||
public String name;
|
private String name;
|
||||||
private boolean manager;
|
private boolean manager;
|
||||||
|
|
||||||
public Employee(String id, String name) {
|
public Employee(String id, String name) {
|
||||||
changeId(id);
|
setPrivateId(id);
|
||||||
this.name = name;
|
setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Employee(String id, String name, boolean managerAttribute) {
|
private Employee(String id, String name, boolean managerAttribute) {
|
||||||
@ -17,7 +17,7 @@ public class Employee {
|
|||||||
this.privateId = id + "_ID-MANAGER";
|
this.privateId = id + "_ID-MANAGER";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeId(String customId) {
|
public void setPrivateId(String customId) {
|
||||||
if (customId.endsWith("_ID")) {
|
if (customId.endsWith("_ID")) {
|
||||||
this.privateId = customId;
|
this.privateId = customId;
|
||||||
} else {
|
} else {
|
||||||
@ -25,7 +25,7 @@ public class Employee {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getPrivateId() {
|
||||||
return privateId;
|
return privateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +43,15 @@ public class Employee {
|
|||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public static Employee buildManager(String id, String name) {
|
public static Employee buildManager(String id, String name) {
|
||||||
return new Employee(id, name, true);
|
return new Employee(id, name, true);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ public class ExampleClass {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Employee employee = new Employee("Bob","ABC123");
|
Employee employee = new Employee("Bob","ABC123");
|
||||||
employee.changeId("BCD234");
|
employee.setPrivateId("BCD234");
|
||||||
System.out.println(employee.getId());
|
System.out.println(employee.getPrivateId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user