Chapter 10: Object-Oriented Programming
TRUE/FALSE
1. Methods in object-oriented programs use sequence, selection, and looping structures and
make use of arrays.
Answer: True
2. In addition to their attributes, class objects have methods associated with them; every
object that is an instance of a class possesses different methods.
Answer: False
3. Within any object-oriented program, you continuously make requests to objects’ methods,
often including arguments as part of those requests.
Answer: True
4. Declaring a class does not create actual objects.
Answer: True
5. Class diagrams are a type of Unified Modeling Language (UML) diagram.
Answer: True
6. The accessor method is another name for the set method.
Answer: False
7. Object-oriented programmers usually specify that their data fields will have private access.
Answer: True
8. All methods require a this reference.
Answer: False
9. No object is necessary with a static method.
Answer: True
10. Methods in a class are static instance methods by default.
Answer: False
MULTIPLE CHOICE
1. ____ is a style of programming that focuses on an application’s data and the methods you
need to manipulate that data.
a. Classical programming
b. Functional programming
c. Procedural programming
d. Object-oriented programming
Answer: D
2. Object-oriented programmers sometimes say an object is one ____ of a class.
a. enumeration
b. instantiation
c. member
d. reference
Answer: B
3. Objects both in the real world and in object-oriented programming contain ____ and
methods.
a. behaviors
b. attributes
c. help
d. primitive data types
Answer: B
4. ____ are the characteristics that define an object as part of a class.
a. Instances
b. Attributes
c. Behaviors
d. Methods
Answer: B
5. When you think in an object-oriented manner, every object is a member of a ____.
a. class
b. struct
c. method
d. collection
Answer: A
6. Object-oriented programmers also use the term ____ when describing inheritance.
a. has-a
b. from-a
c. is-a
d. contains
Answer: C
7. The concept of a class is useful because of its ____.
a. reusability
b. mapping to reality
c. abstract nature
d. portability
Answer: A
8. Object attributes are often called ____ to help distinguish them from other variables you
might use.
a. rows
b. records
c. columns
d. fields
Answer: D
9. The data components of a class that belong to every instantiated object are the class’s
____.
a. numeric variables
b. string variables
c. instance variables
d. data variables
Answer: C
10. A(n) ____ is a program or class that instantiates objects of another prewritten class.
a. instantiation
b. method
c. class client
d. class definition
Answer: C
11. The term ____ is applied to situations in which you define multiple methods with a single
name.
a. overloading
b. bonding
c. renaming
d. inferring
Answer: A
12. A ____ is a set of program statements that tell you the characteristics of the class’s
objects and the methods that can be used by its objects.
a. class interface
b. class definition
c. class reference
d. class model
Answer: B
13. The term ____ implies that the type’s data can be accessed only through methods.
a. abstract type library
b. advanced data type
c. abstract definition type
d. abstract data type
Answer: D
14. A(n) ____ is a programmer-defined type, such as a class.
a. inheritance
b. numeric data type
c. primitive data type
d. abstract data type
Answer: D
15. In older object-oriented programming languages, simple numbers and characters are said
to be ____ data types.
a. primitive
b. simple
c. complex
d. higher-order
Answer: A
16. A(n) ____ consists of a rectangle divided into three sections.
a. class tree
b. dependency diagram
c. class diagram
d. entity-relationship diagram
Answer: C
17. The purpose of ____ is to set the values of data fields within the class.
a. get methods
b. put methods
c. make methods
d. set methods
Answer: D
18. Methods that set values are called ____ methods.
a. modifier
b. mutator
c. creator
d. access
Answer: B
19. The purpose of a(n) ____ is to return a value to the world outside the class.
a. get method
b. set method
c. pull method
d. access method
Answer: A
20. A ____ method is also known as a help method.
a. work
b. private
c. public
d. set
Answer: A
21. A(n) ____ is the adjective defining the type of access (public or private) that outside
classes will have to the attribute or method.
a. control specifier
b. control modifier
c. access specifier
d. access controller
Answer: C
22. In a class method, the ____ reference can be used only with identifiers that are field
names.
a. my
b. this
c. that
d. me
Answer: B
23. ____ methods are those for which no object needs to exist.
a. Dynamic
b. Public
c. Static
d. Private
Answer: C
24. ____ methods are methods that exist to be used with an object created from a class.
a. Nonstatic
b. Static
c. Hidden
d. Controlled
Answer: A
25. In most programming languages, you use the word ____ when you want to declare a
static class member.
a. private
b. friend
c. public
d. static
Answer: D
COMPLETION
1. A(n) ____________________ is one instance of a class.
Answer: object
2. When you think in an object-oriented manner, everything is a(n) ____________________.
Answer: object
3. When you program in object-oriented languages, you frequently create
____________________ from which objects will be instantiated.
Answer: classes
4. With object-oriented programming, you focus on the ____________________ that will be
manipulated by the program.
Answer: objects
object
5. Any time a local variable in a method has the same identifier as a class field, the class field
is ____________________.
Answer: hidden
MATCHING
Match each term with a statement below.
1. Describes a group or collection of objects with common attributes a. instance variables
2. An instance of a class b. class client
3. The characteristics that define an object as part of a class c. inheritance
4. The data components of a class that belong to every instantiated object d. class
5. The set of all the values or contents of a class object’s instance variables e. information
hiding
6. A program or class that instantiates objects of another prewritten class f. state
7. Multiple methods with the same name, which will act differently and appropriately when
used with different types g. polymorphism
8. The process of acquiring the traits of one’s predecessors h. attributes
9. The process of combining all of an object’s attributes and methods into a single package i.
encapsulation
10. The concept that other classes should not alter an object’s attributes—only the methods of
an object’s own class should have that privilege j. object
1. Answer: D
2. Answer: J
3. Answer: H
4. Answer: A
5. Answer: F
6. Answer: B
7. Answer: G
8. Answer: C
9. Answer: I
10. Answer: E
SHORT ANSWER
1. List five important features of object-oriented languages.
Answer: Five important features of object-oriented languages are:
• Classes
• Objects
• Polymorphism
• Inheritance
• Encapsulation
2. Discuss why it is helpful to think of items as instances of a class.
Answer: Thinking of items as instances of a class allows you to apply your general
knowledge of the class to its individual members. A particular instance of an object takes its
attributes from the general category.
3. Discuss why the reusability of a class makes it useful.
Answer: The concept of a class is useful because of its reusability. For example, if you invite
me to a graduation party, I automatically know many things about the object (the party). I
assume there will be attributes such as a starting time, a number of guests, some quantity of
food, and some nature of gifts. I understand parties because of my previous knowledge of the
Party class, of which all parties are members. I don’t know the number of guests or the date
or time of this particular party, but I understand that because all parties have a date and time,
then this one must as well. Similarly, even though every stock purchase is unique, each must
have a dollar amount and a number of shares. All objects have predictable attributes because
they are members of certain classes.
4. Explain encapsulation and information hiding.
Answer: Real-world objects often employ encapsulation and information hiding.
Encapsulation is the process of combining all of an object’s attributes and methods into a
single package. Information hiding is the concept that other classes should not alter an
object’s attributes—only the methods of an object’s own class should have that privilege.
Outside classes should only be allowed to make a request that an attribute be altered; then it
is up to the class’s methods to determine whether the request is appropriate. When using a
door, you usually are unconcerned with the latch or hinge construction features, and you
don’t have access to the interior workings of the knob or know what color of paint might
have been used on the inside of the door panel. You care only about the functionality and the
interface, the user-friendly boundary between the user and internal mechanisms of the device.
Similarly, the detailed workings of objects you create within object-oriented programs can be
hidden from outside programs and modules if you want them to be. When the details are
hidden, programmers can focus on the functionality and the interface, as people do with reallife objects.
5. List the three parts of a class definition.
Answer: A class definition can contain three parts:
• Every class has a name.
• Most classes contain data, although this is not required.
• Most classes contain methods, although this is not required.
6. Describe what class diagrams list by convention.
Answer: By convention, a class diagram lists the names of the data items first. Each name is
followed by a colon and the data type. Similarly, method names are followed by their data
types. Listing the names first emphasizes the purposes of the fields and methods more than
their types.
7. Explain what private access means in object-oriented programming.
Answer: Object-oriented programmers usually specify that their data fields will have private
access—that is, the data cannot be accessed by any method that is not part of the class.
8. List the two identifiers within a method that always mean exactly the same thing when you
write an instance method in a class.
Answer: When you write an instance method in a class, the following two identifiers within
the method always mean exactly the same thing:
• any field name defined in the class
• this, followed by a dot, followed by the same field name
9. Describe what happens any time a local variable in a method has the same identifier as a
class field.
Answer: Any time a local variable in a method has the same identifier as a class field, the
class field is hidden. This applies whether the local variable is a passed parameter or simply
one that is declared within the method. In these cases, you must use a this reference to refer to
the class field.
10. Discuss nonstatic methods.
Answer: Nonstatic methods are methods that exist to be used with an object. These instance
methods receive a this reference to a specific object. In most programming languages, you
use the word static when you want to declare a static class member, but you do not use a
special word when you want a class member to be nonstatic. In other words, methods in a
class are nonstatic instance methods by default.
Testbank for Programming Logic and Design
Joyce Farrell