I need help trying to figure out how to use constructors...
In one example we are supposed to do the following:
You are given a class named Clock that has one int instance variable called hours . Write a constructor for the class Clock that takes one parameter , an int , and gives its value to hours.
I just can't figure out how to take a parameter and assign it to "hours"??
In another example we had to:
You are given a class named Clock that has one int instance variable called hours . Write a constructor with no parameters for the class Clock . The constructor should set hours to 12 .
Now, I get this...
Clock ()
{
hours = 12;
}
That's simple enough, but I can't seem to take the leap from there to take a parameter and give its value to hours. Maybe this is just me overthinking the whole situation, but any tips or assistance would be greatly appreciated.
Thanks,
Susan
In one example we are supposed to do the following:
You are given a class named Clock that has one int instance variable called hours . Write a constructor for the class Clock that takes one parameter , an int , and gives its value to hours.
I just can't figure out how to take a parameter and assign it to "hours"??
In another example we had to:
You are given a class named Clock that has one int instance variable called hours . Write a constructor with no parameters for the class Clock . The constructor should set hours to 12 .
Now, I get this...
Clock ()
{
hours = 12;
}
That's simple enough, but I can't seem to take the leap from there to take a parameter and give its value to hours. Maybe this is just me overthinking the whole situation, but any tips or assistance would be greatly appreciated.
Thanks,
Susan
