Method chaining in the Builder pattern works by having each setter-style method return the builder instance itself, so multiple configuration calls can be strung together into a single fluent expression that ends with a build() call.
Calling `new PersonBuilder().name("Amol").age(30).city("Pune").build()` reads naturally as a single statement, where each method call configures one field and hands control back to continue the chain.
class PersonBuilder {
private String name;
private int age;
PersonBuilder name(String name) {
this.name = name;
return this;
}
PersonBuilder age(int age) {
this.age = age;
return this;
}
Person build() {
return new Person(name, age);
}
}A concise interview answer is
Method chaining works because every builder method sets a field and returns the builder object itself, letting you string calls together into one fluent expression that finishes with build(), which constructs the final object — it reads cleanly and avoids constructors with long parameter lists.
Last updated: 16 July 2026
Previous question: What are the benefits of using the Builder pattern for constructing complex objects?
Next question: Provide an example of when using a Builder pattern is preferable over multiple constructors.