public class Employee {
public String name;
public int age;
public int salary;
Employee withName(String name){
this.name = name;
return this;
}
Employee withAge(int age){
this.age = age;
return this;
}
Employee withSalary(int salary){
this.salary = salary;
return this;
}
}
public class BuilderPatternTest {
public static void main(String[] args) {
Employee employee = new Employee().withName("John").withAge(25).withSalary(10000);
}
}
|