Monday, March 23, 2015

Constructor overloading

Like methods, constructors can also be overloaded. Constructor overloading in java allows to have more than one constructor inside one Class


Examples:

public class TimeOfDay1c { public int hour; public int minute; //==================================================== constructor public TimeOfDay1c(int h, int m) { hour = h; minute = m; } //==================================================== constructor public TimeOfDay1c(int h) { hour = h; minute = 0; // Set minutes to 0. }}


No comments:

Post a Comment