Last active
May 11, 2016 11:36
-
-
Save vojtechruz/6f68a37dc09e962aa1a228822f51fe3d to your computer and use it in GitHub Desktop.
Example of telescoping constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
private final String firstName; | |
private final String lastName; | |
private final String description; | |
private final int age; | |
public Person(String firstName, String lastName) { | |
this(firstName, lastName, "No description available"); | |
} | |
public Person(String firstName, String lastName, String description) { | |
this(firstName, lastName, description, -1); | |
} | |
public Person(String firstName, String lastName, String description, int age) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.description = description; | |
this.age = age; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment