October 2017
Beginner
318 pages
7h 26m
English
Now, let's go back to talking about constructors before we wrap up. As with normal methods, we can override constructors and have more than one option for our programmer to choose from.
For example, let's say that sometimes in our program, we want to create new people who have just been born. In this instance, it might make a lot of sense for us to construct a person by simply giving firstName and lastName to our constructor and then having birthday as new Gregorian Calendar, which will default to today's date:
package gettingobjectoriented; import java.util.*; public class Person { private String firstName; private String lastName; private Calendar birthday; public Person(String firstName, String lastName) { this.firstName ...Read now
Unlock full access