This is a question from a java based code lab, and they arenot telling me where
ID: 3613986 • Letter: T
Question
This is a question from a java based code lab, and they arenot telling me where I am going wrong with the answer. The question is: You are given a class named Clock that has one intinstance variable called hours . Write a constructor for theclass Clock that takes one parameter, an int , andgives its value to hours . Here is the answer I currently have: public Clock(int hours){class.hours = hours;} Can you please help with solving this issue. This is a question from a java based code lab, and they arenot telling me where I am going wrong with the answer. The question is: You are given a class named Clock that has one intinstance variable called hours . Write a constructor for theclass Clock that takes one parameter, an int , andgives its value to hours . Here is the answer I currently have: public Clock(int hours){class
.hours = hours;} Can you please help with solving this issue.
Explanation / Answer
private static int hours;this.hours = hours; // use this to refer to instance ofclock
} public static void main(String[] a){
Clock c = new Clock(4); //makes anew instance of clock class with the hour variable set to 4
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.