some body said the answer is b , and the other said its d, so, I got confused .
ID: 3594980 • Letter: S
Question
some body said the answer is b , and the other said its d, so, I got confused .
in Java language
the quistion is
Q: We want to create a class that represents a clock. A clock has hour, minute, and second. For example, the time 12:15:36 means, it is 12 o’clock, 15 minutes, and 36 seconds. The basic framework of a Clock class is below: public class Clock { private int hour; private int minutes; private int seconds; } 1. What should the body of the constructor be? A. hr = hour; min = minutes; sec = seconds; B. hour = 12; minutes = 15; seconds = 36; C. int hour = hr; int minutes = min; int seconds = sec; D. hour = hr; minutes = min; seconds = sec;
Explanation / Answer
The requirement is to create the framework for a clock. The time 12:15:36 was given as an example, so the option containing the direct hard coded values 12, 15, 36 is no the correct option(b). So the correct option is d only.
Here I have explained how it can be:
Generally in Java classes important variable are declared as private and they will be initialized inside the constructor and getter, setter methods are used to acces them. This will be for the purpose of Encapasulation(Strongly believing you are aware of this OOPS concept). Below is peice of code how your constructor should look like.
public class ClockFrame {
private int hour;
private int minutes;
private int seconds;
public ClockFrame(int hr, int min, int sec) {
hour = hr;
minutes = min;
seconds = sec;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.