← Quiz: Creational Patterns in Java: all 10 questions
Quiz: Creational Patterns in Java · Question 9 of 10
Why does each Builder setter return this?
Why does each Builder setter return this?
- A.To create a new builder each time
- B.To return the finished object
- C.So calls can be chained:
.email(...).hostel(true).build() - D.Java requires setters to return a value
Answer & explanation
Correct answer: So calls can be chained: .email(...).hostel(true).build()
Returning the same builder lets you call the next method on it.
Can you get the rest right without peeking?
Take the timed Quiz: Creational Patterns in Java quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →