April 2019
Intermediate to advanced
360 pages
9h 17m
English
When constructors and methods are declared, we include the expected parameters. For example, our Bicycle() constructor does not take any parameters. We can overload that constructor by creating one or more versions of it, each with a different set of parameters. Let's look at our Bicycle class with four constructors:
// constructor - defaultBicycle() {}// constructor - String parameterBicycle(String aColor) { this.color = aColor;}// constructor - int parameterBicycle(int nbrOfGears) { this.gears = nbrOfGears;}// constructor - int, double, double, String parametersBicycle(int nbrOfGears, double theCost, double theWeight, String aColor) { this.gears = nbrOfGears; this.cost = theCost; this.weight = theWeight; ...
Read now
Unlock full access