Multiple Choice Answers

1. Which of the following would be the most appropriate choice for a method in a PhoneChargerclas
Voltage()
Manufacturer()
Current()
Charge()

2. Which of the following statements is/are true? (Points : 5)
A. The implementation details of a class can change, so they need to be visible.
B. An object is necessary to be defined before you can create a class.
C. The state of an object is defined as the attributes and behaviors of that object.
D. An interface of a class defines what messages an object can respond to.
All are true
None are true
Only A, C, and D are true

3. Which of the following components of a class definition cannot be overloaded? (Points : 5)
Public member methods
Destructors
Constructors
Private member methods
All of the above

4.  Which of the following statements is/are true? )
A. A private (helper) method can only be used inside the class. It cannot be called through an object of the class.
B. The programmer can control the scope of a data member of a class using access specifiers.
C. The state of an object must be hidden and therefore protected by unauthorized use.
All of the above
Only A and C

5. Which of the following method pairs are not examples of method overloading?)
A. public void Bake() ; public int Bake()
B. public int Mix(int x, int y) ; public int Mix(int y, int x)
C. public int Shake(int x, int y) ; public int Shake(int x, int y, int z)
None of the above
Only A and B

6. (TCO 1) Which of the following statements is/are false? (Points : 5)
Member methods are the means by which you implement the behavior of a class.
By using the keyword class in your program, memory is allocated for the object being defined.
Objects are created during program execution and eventually destroyed.
None of the above

7. (TCO 2) Assume you implemented a class called Automobile last year. You made sure to design Automobile to include the concept of encapsulation. Now, you need to change the name of one of your private class attributes. Because you used the concept of encapsulation and followed best practices when designing your class, only the _____ and _____ need to be changed.
getters; setters
access modifiers; constructors
data type; return values
public attributes; private methods
None of the above

8. (TCO 2) A black box is a term used to describe a system that can be understood solely based on its inputs, a description of its _____ and the resulting outputs.
processing
inherited processes
attributes
accessors

9. (TCO 2) Given a private attribute called hairColor, which of the following are proper pseudocode implementations for a getter and a setter?)
string getHairColor(){return hairColor}
intsetHairColor(string newHairColor){return hairColor}
void getHairColor(){return hairColor}
void setHairColor (intnewHairColor){hairColor = newHairColor}
string getHairColor(){return hairColor}
void setHairColor (string newHairColor){hairColor = newHairColor}
string getHairColor (){hairColor = newHairColor}
void setHairColor (string newHairColor){hairColor = newHairColor}

10. Which of the following statements is true?)
Interfaces must implement a default constructor if even one multi-arg constructor is also implemented.
Interfaces are defined and implemented inside an abstract class.
Methods listed in an interface must be implemented when used by another class.
At least one interface should be used in any inheritance hierarchy.

11.  Which of the following statements is/are true?
Interfaces contain both implemented methods and constants.
Abstract classes always contain at least one interface.
Derived classes can inherit abstract methods.
None of the above

12. (TCO 7) Programmers may be forced to adhere to a contract or a specification defined by a framework due to the use of _____ and _____.
abstract classes; constants
abstract classes; interfaces
base classes; abstract methods
has-a; is-a relationships
None of the above

13. (TCO 4) If you have a complete, working Employee class that has been thoroughly tested, and you wish to add an overloaded getSalary() method that can calculate the salary of a Manager which is the total of salary and bonus, how should this be accomplished?
Make a brand new class.
Add the method to your existing Employee class.
Add the method in the same class as the Main method.
Derive a new Manager class from the first Employee class and add it there.

14. (TCO 3) A Ball class and a Baseball class have what type of relationship?
(Points : 5)
The Ball is-a Baseball.
The Baseball is-a Ball.
The Ball has-a Baseball
The Baseball has-a Ball.

15. (TCO 4) In what type(s) of situation(s) would it be best to make a new derived class from a base class?)
A. When your current class is a general form of what your new class should be
B. When you need to create a specialized class from an existing class
A and B
None of the above