Question: Overloaded Constructors a) Implement a Weight class with a two-parameter setWeight method that initializes weight and units variables and a one-parameter setWeight method that uses
Overloaded Constructors
a) Implement a Weight class with a two-parameter setWeight method that initializes weight and units variables and a one-parameter setWeight method that uses a default “kg” for units. Provide corresponding two- parameter and one-parameter constructors and a print method, which displays weight and units values. Minimize the total number of statements by having the one-parameter constructor call the one- parameter setWeight method and the two-parameter constructor call the two-parameter setWeight method.
b) Provide a main method for a WeightDriver class such that the new main method uses one of the new constructors from part a) to generate this output:
120 lbs
Step by Step Solution
3.32 Rating (149 Votes )
There are 3 Steps involved in it
lets create the Weight class This class will contain two variables weight and units Well also create ... View full answer
Get step-by-step solutions from verified subject matter experts
