{ // Example 1: Creating a user in a single line UserProfile user1 = new UserProfileBuilder("alice123") .email("alice@example.com") .phoneNumber("555-1234") .address("123 Main St, NY") .age(25) .build(); // Example 2: Building the object step by step UserProfileBuilder builder = new UserProfileBuilder("bob456"); builder.email("bob@example.com").phoneNumber("555-5678"); UserProfile user2 = builder.address("456 Elm St, LA").age(30).build(); System.out.println(user1); System.out.println(user2); } } 9
javiergs@calpoly.edu Winter 2025 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.