public class FullName {
private final String firstName;
private final String lastName;
public static class Builder{
private String firstName;
private String lastName;
public Builder(){}
public Builder firstName(String firstName){
this.firstName = firstName;
return this;
}
public Builder lastName(String lastName){
this.lastName = lastName;
return this;
}
public FullName build(){
return new FullName(this);
}
}
private FullName(Builder builder) {
firstName = builder.firstName;
lastName = builder.lastName;
}
}
Client code
FullName name = new FullName.Builder().firstName("Ming").lastName("Sun").build();