Preview (3 of 10 pages)

Preview Extract

Chapter 11: More Object-Oriented Programming Concepts
TRUE/FALSE
1. In object-oriented terminology, “default constructor” means a constructor with a single
standard parameter.
Answer: False
2. In OO languages, a default constructor is created automatically by the compiler for every
class you write.
Answer: True
3. Any constructor you write must have the same name as the class it constructs, and it cannot
have a return type.
Answer: True
4. You can write a default constructor, which is a constructor that accepts parameters.
Answer: False
5. You cannot provide parameters to a destructor; it must have an empty parameter list.
Answer: True
6. It makes sense that a parent class object has access to its child’s data and methods.
Answer: False
7. By using standard component classes, programmers are assured that the GUI components
in their programs have the same look and feel as those in other programs.
Answer: True
8. The built-in Exceptions in a programming language can cover every condition that might
be an Exception in your applications.
Answer: False
9. Whether you instantiate objects from classes you have created or from those created by
others, you save development time because each object automatically includes appropriate,
reliable methods and attributes.
Answer: True
10. When using existing objects, you need to concentrate only on the interface to those
objects, not on the internal instructions that make them work.
Answer: True
MULTIPLE CHOICE
1. If a constructor requires arguments, it is a ____ constructor.
a. reliable

b. private
c. default
d. nondefault
Answer: D
2. A method’s name and a list of argument types together are its ____.
a. signature
b. header
c. profile
d. interface
Answer: A
3. The most common way to declare a destructor explicitly is to use an identifier that consists
of ____.
a. a colon followed by the class name
b. a period followed by the class name
c. a tilde followed by the class name
d. an exclamation mark followed by the class name
Answer: C
4. The relationship created with composition is called a(n) ____ relationship.
a. is-a
b. has-a
c. with-a
d. child
Answer: B
5. A(n) ____ in a class diagram indicates public access.
a. minus sign
b. diamond
c. plus sign
d. exclamation point
Answer: C
6. A(n) ____ in a class diagram indicates private access.
a. minus sign

b. plus sign
c. exclamation point
d. period
Answer: A
7. When properly used, inheritance always involves a ____ relationship.
a. specific-to-general
b. general-to-specific
c. specific-to-specific
d. general-to-general
Answer: B
8. A class that is used as a basis for inheritance is called a ____ class.
a. base
b. bottom
c. platform
d. derived
Answer: A
9. A derived class always ____ case or instance of the more general base class.
a. has a
b. makes a
c. redefines a
d. is a
Answer: D
10. The entire list of parent classes from which a child class is derived constitutes the ____ of
the subclass.
a. children
b. ancestors
c. subordinates
d. derivatives
Answer: B
11. In some programming languages, such as C#, Visual Basic, and Java, every class you
create is a child of one ultimate base class, often called the ____ class.

a. Top
b. Object
c. Ultimate
d. Mega
Answer: B
12. When a data field within a class is ____, no outside class can use it—including a child
class.
a. reliable
b. fragile
c. private
d. protected
Answer: C
13. Classes that depend on field names from parent classes are said to be ____ because they
are prone to errors.
a. robust
b. innovative
c. fragile
d. constructive
Answer: C
14. The capability to inherit from more than one class is called ____ inheritance.
a. weak
b. multiple
c. modified
d. simple
Answer: B
15. Code that has already been tested and used in a variety of situations is said to be ____.
a. protected
b. private
c. overloaded
d. reliable
Answer: D

16. In several languages, the visual development environment is known by the acronym ____.
a. IDE
b. XML
c. ODI
d. IPE
Answer: A
17. When you purchase or download a(n) ____ for an object-oriented programming language,
it comes packaged with many predefined, built-in classes.
a. compiler
b. IDE
c. sunny day case
d. interpreter
Answer: A
18. Programmers use the phrase ____ to describe what happens when worthless or invalid
input causes inaccurate or unrealistic results.
a. WIGO
b. GOGI
c. LIFO
d. GIGO
Answer: D
19. In traditional programming, probably the most often used error-handling outcome was to
____.
a. terminate the program in which the offending statement occurred
b. ignore the error
c. handle the error
d. ask the user for additional input
Answer: A
20. Object-oriented programs employ a more specific group of techniques for handling errors
called ____.
a. exception raising
b. exception management
c. exception handling

d. garbage collection
Answer: C
21. In object-oriented terminology, an ____ is an object that represents an error.
a. interference
b. undefined branch
c. interface
d. exception
Answer: D
22. If an exception is thrown, it is passed to a block of code that can ____, which means to
receive it in a block that can handle the problem.
a. catch the exception
b. raise the exception
c. hold the exception
d. try the exception
Answer: A
23. When you create a segment of code in which something might go wrong, you place the
code in a ____ block.
a. throw
b. hold
c. try
d. catch
Answer: C
24. Programmers sometimes refer to a situation in which nothing goes wrong as the ____
case.
a. rainbow day
b. sunny day
c. cloudy day
d. pessimistic
Answer: B
25. By using ____, you can use reasonable, easy-to-remember names for methods and
concentrate on their purpose rather than on memorizing different method names.
a. inheritance

b. inference
c. polymorphism
d. relationships
Answer: C
COMPLETION
1. A(n) ____________________ method is a method that establishes an object.
Answer: constructor
2. An instance of a class becomes eligible for destruction when it is no longer possible for
any code to use it—that is, when it goes out of ____________________.
Answer: scope
3. Libraries, collections of classes that serve related purposes, are also called
____________________.
Answer: packages
4. You almost always code at least one catch block immediately following a(n)
____________________ block.
Answer: try
5. When using ____________________, you can develop new classes more quickly by
extending classes that already exist and work.
Answer: inheritance
MATCHING
Match each term with a statement below.
1. A method that has the same name as a class and that establishes an object a. exceptions
2. Contains the actions you require when an instance of a class is destroyed b. composition
3. Placing a class object within another class object c. abstract
4. Used when you want no outside classes to be able to use a data field, except classes that
are children of the original class d. try block
5. A class from which you cannot create any concrete objects, but from which you can inherit
e. destructor
6. Collections of classes that serve related purposes f. libraries
7. Errors in object-oriented languages g. catch block
8. Sends an Exception object out of the current code block or method so it can be handled
elsewhere h. protected access specifier

9. A block of code you attempt to execute while acknowledging that an exception might
occur i. throw statement
10. A segment of code that can handle an exception that might be thrown by the try block that
precedes it j. constructor
1. Answer: J
2. Answer: E
3. Answer: B
4. Answer: H
5. Answer: C
6. Answer: F
7. Answer: A
8. Answer: I
9. Answer: D
10. Answer: G
SHORT ANSWER
1. Explain constructors.
Answer: A method that has the same name as a class and that establishes an object is a
constructor method, or more simply, a constructor. A default constructor is one that requires
no arguments. If a constructor requires arguments, it is a nondefault constructor. In objectoriented programming (OOP) languages, you can write both default and nondefault
constructors; but if you do not create either, then a default constructor is created
automatically by the compiler for every class you write.
2. Explain composition.
Answer: A class can contain objects of another class as data members. For example, you
might create a class named Date that contains a month, day, and year, and add two Date fields
to an Employee class to hold the Employee’s birth date and hire date. Then you might create
a class named Department that represents every department in a company, and create each
Department class member to contain a supervisor, who is an Employee. When a class
contains objects of another class, the relationship is called a whole-part relationship or
composition. The relationship created is also called a has-a relationship because one class
“has an” instance of another.
3. Explain inheritance.
Answer: Inheritance enables you to apply your knowledge of a general category to more
specific objects. When you use the term inheritance, you might think of genetic inheritance.
You know from biology that your blood type and eye color are the products of inherited
genes. You might choose to own plants and animals based on their inherited attributes. You
plant impatiens next to your house because they thrive in the shade; you adopt a poodle

because you know poodles don’t shed. Every plant and pet has slightly different
characteristics; but within a species, you can count on many consistent inherited attributes
and behaviors. In other words, you can reuse the knowledge you gain about general
categories and apply it to more specific categories.
4. Describe the Object class.
Answer: In some programming languages, such as C#, Visual Basic, and Java, every class
you create is a child of one ultimate base class, often called the Object class. The Object class
usually provides you with some basic functionality that all the classes you create inherit—for
example, the ability to show its memory location and name.
5. List three advantages of creating a useful, extendable superclass.
Answer: Subclass creators save development time because much of the code needed for the
class has already been written.
Subclass creators save testing time because the superclass code has already been tested and
probably used in a variety of situations. In other words, the superclass code is reliable.
Programmers who create or use new subclasses already understand how the superclass works,
so the time it takes to learn the new class features is reduced.
When you create a new subclass, neither the superclass source code nor the translated
superclass code is changed. The superclass maintains its integrity.
6. Discuss exception handling.
Answer: Object-oriented programs employ a group of techniques for handling errors called
exception handling. The generic name used for errors in object-oriented languages is
exceptions because errors are not usual occurrences; they are the “exceptions” to the rule.
In object-oriented terminology, you try some code that might throw an exception. If an
exception is thrown, it is passed to a block of code that can catch the exception, which means
to receive it in a way similar to how a parameter is received by a method.
7. Describe the components of a try block.
Answer: A try block consists of the keyword try, followed by any number of statements,
including some that might cause an exception to be thrown. If a statement in the block causes
an exception, the remaining statements in the try block do not execute and the try block is
abandoned. For pseudocode purposes, you can end a try block with a sentinel such as endtry.
8. List the elements you would use to create a catch block.
Answer: The keyword catch, followed by parentheses that contain an Exception type and an
identifier
Statements that take the action you want to use to handle the error condition
An endcatch statement to indicate the end of the catch block in the pseudocode
9. Discuss the general principle of exception handling in object-oriented programming.

Answer: The general principle of exception handling in object-oriented programming is that a
method that uses data should be able to detect errors, but not be required to handle them. The
handling should be left to the application that uses the object, so that each application can use
each method appropriately.
10. Explain how to create your own throwable Exception.
Answer: To create your own throwable Exception, you usually extend a built-in Exception
class. For example, you might create a class named NegativeBankBalanceException or
EmployeeNumberTooLargeException. By inheriting from the Exception class, you gain
access to methods contained in the parent class, such as those that display a default message
describing the Exception.

Test Bank for Programming Logic and Design
Joyce Farrell
9781111969752, 9788131525906, 9781111825959

Document Details

Related Documents

Close

Send listing report

highlight_off

You already reported this listing

The report is private and won't be shared with the owner

rotate_right
Close
rotate_right
Close

Send Message

image
Close

My favorites

image
Close

Application Form

image
Notifications visibility rotate_right Clear all Close close
image
image
arrow_left
arrow_right