Académique Documents
Professionnel Documents
Culture Documents
Song[] music;
1
5. An immutable class cannot have _______.
6. Assume an employee should work for one and only one company. What is the best
suitable relationship between class Company and class Employee?
A. Encapsulation
B. Aggregation
C. Inheritance
D. Composition
7. You can declare two variables with the same name __________.
class Circle {
private double radius;
A. The program has a compilation error because it does not have a main method
B. The object of this class will always have radius 0
C. The program has a compilation error because you cannot assign radius to radius
D. The program does not compile because Circle does not have a default constructor
2
9. Which of the following statements is correct?
A. A method can be overridden in the same class
B. If a method overloads another method, these two methods must have the same
signature and return type
C. If a method overrides another method, these two methods must have the same
signature and return type
D. A method in a subclass cannot overload a method in the superclass
3
Section B: Programming Questions
(a) A Room is an abstract class that has two data members, humidity and temperature, to indicate
the conditions of the room and both are private and type double. This class has one
constructor that accepts both humidity and temperature as arguments and set the object's
humidity and temperature accordingly. BedRoom and LivingRoom are two concrete
subclasses of the Room class. Create the three classes and provide appropriate accessor and
mutator methods for the classes.
(b) IOperate is an interface that defines a single method control(Room r), which is used to
control the humidity and temperature of a room.
(c) An AirCond (air conditioner) class implements the IOperate interface and reduces the room
temperature and humidity level every time the control(Room r) method is called. If the room
object is a BedRoom, then the control method reduces the temperature and humidity of the
bedroom by 10. If the room object is a LivingRoom, it reduces the living room’s temperature
and humidity by 5. Create the AirCond class according to the above description.
(d) Draw the UML class diagram that shows the relationships of the above classes. Your class
diagram should provide details of all the data members and methods of each class