I am attempting to write a 2-paramter constructor that meets the following specifications: /** * Creates a new digital clock with the time set at the given * hours and minutes. * * @precondition 0 <= hour <= 23 AND 0 <= minutes <= 59 * @postcondition getHour()==hour AND getMinutes()==minutes * * @param hour the hour to set for the time * @param minutes the minutes to set for the time */ I forget how to write a constructor and would appreciate some assitance as to how I can do so in accordance with these specifications. I know it is something along the lines of public INSERTNAME(parameter 1, paratmer 2) { }
I am attempting to write a 2-paramter constructor that meets the following specifications:
/**
* Creates a new digital clock with the time set at the given
* hours and minutes.
*
* @precondition 0 <= hour <= 23 AND 0 <= minutes <= 59
* @postcondition getHour()==hour AND getMinutes()==minutes
*
* @param hour the hour to set for the time
* @param minutes the minutes to set for the time
*/
I forget how to write a constructor and would appreciate some assitance as to how I can do so in accordance with these specifications. I know it is something along the lines of public INSERTNAME(parameter 1, paratmer 2) { }

A constructor is a unique method that is used to initialize objects. The constructor is called automatically as soon as the object is defined. It is also used to set the initial values of an object.
One more thing to remember is a constructor name will be the same as the class name.
for example,
class Driver
{
int speed;
public Driver() //constructor
{
speed = 5; //setting initial value of attribute
}
};
Step by step
Solved in 2 steps









