Objects and Classes - Quiz Explanation
The answers you selected are indicated below, along with text that explains the correct answers.
1.
Consider a class called Date that represents an individual date. Which of the following could be an object that is an instance of the Date class?
Please select the best answer.
A.
Wednesdays
B.
January 17, 2001
C.
January 2001
D.
January 17-21, 2001
The correct answer is B.
It represents an individual date. A, C, and D are incorrect because they represent multiple dates or a range of dates. Consider this object diagram for a Money class: Here is the HTML from the current course for the diagram:
salary:Money
dollars: 876
cents: 34
2.
Which of the following items in the diagram is an attribute of the class?
Please select the best answer.
A.
salary
B.
Money
C.
dollars
D.
876
The correct answer is C.
Both dollars and cents are attributes of this class. A is incorrect because salary is the name of an object in the class, not an attribute. B is incorrect because Money is the name of the class itself, not an attribute. D is incorrect because 876 is a value of an attribute, not the attribute itself.
3.
Consider this class diagram for a Date class:
Date
year: Integer
month: Integer
day: Integer
Which of the following is a correct object diagram for a Date object named Christmas set to December 25, 1999?
Please select the best answer.
A.
date: Date
year: 1999
month: 12
day: 25
B.
Christmas: Date
day: 25
month: 12
year: 1999
C.
Christmas:Date
year: 1999
month: December
day: 25
D.
:Date
year: 1999
month: December
day: 25
The correct answer is B.
A is incorrect because it use the wrong name for the object (date instead of Christmas). C is incorrect because the value of the month is given as a string data type instead of the integer specified in the object diagram. D is incorrect because it does not show the name of the object next to the class name.