Chapter 06 – A First Look At Classes
Multiple Choice
1. One or more objects may be created from a(n)_____.
a. field
b. class
c. method
d. instance
ANS: B
2. Class objects normally have _____ that perform useful operations on their data, but primitive variables do not.
a. fields
b. instances
c. methods
d. relationships
ANS: C
3. In the cookie cutter method: Think of the _____ as a cookie cutter and _____ as the cookies.
a. object; classes
b. class; objects
c. class; fields
d. field; methods
ANS: B
4. A UML diagram does not contain _____.
a. class name
b. methods
c. fields
d. object names
ANS: D
5. An access specifier indicates how the class may be accessed.
a. True
b. False
ANS: A
6. Data hiding, which means that critical data stored inside the object is protected from code outside the object is accomplished in Java by _____.
a. using the public access specifier on the class methods
b. using the private access specifier on the class methods
c. using the private access specifier on the class definition
d. using the private access specifier on the class fields
ANS: D
7. For the following code, which statement is not true? public class Sphere
{
private double radius; public double x; private double y; private double z;
}
a. x is available to code that is written outside the Sphere class.
b. radius is not available to code written outside the Sphere class.
c. radius, x, y, and z are called members of the Sphere class.
d. z is available to code that is written outside the Sphere class.
ANS: D
8. Which of the following is not part of the method header?
a. Method name
b. Return type
c. Access specifier
d. Parameter variable declaration
e. All of the above are parts of the method header
ANS: E
9. A method that stores a value in a class’s field or in some other way changes the value of a field is known as a