365,395 views
36 votes
36 votes
you are given a class named clock that has one int field named hours. write a constructor with no parameters for the clock class. the constructor should set hours to 12.

User Bioukh
by
2.9k points

1 Answer

25 votes
25 votes

//Class definition.

class Clock{

public:

int hours;

//Constructor syntax.

// current_class_name + (parameters if needed) {...}

Clock() {

//Set the hour as 12.

hours=12;

}

};

User Silvado
by
3.0k points