Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- private String firstName;
- private String secondName;
- private String lastName;
- private int age;
- private String address;
- private Person(String firstName, String lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- }
- public static Person of(String firstName, String lastName) {
- return new Person(firstName, lastName);
- }
- public Person secondName(String secondName) {
- this.secondName = secondName;
- return this;
- }
- public Person age(int age) {
- this.age = age;
- return this;
- }
- public Person address(String address) {
- this.address = address;
- return this;
- }
- @Override
- public String toString() {
- return "Person{" +
- "firstName='" + firstName + '\'' +
- ", secondName='" + secondName + '\'' +
- ", lastName='" + lastName + '\'' +
- ", age=" + age +
- ", address='" + address + '\'' +
- '}';
- }
- }
- public class Main {
- public static void main(String[] args) {
- Person john = Person.of("John", "Smith").secondName("William").age(30);
- System.out.println(john);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement