Java How to Program, 11/e Multiple Choice Test Bank 1 of 11
Chapter 10: Object-Oriented
Programming: Polymorphism
Section 10.1 Introduction
10.1 Q1: Polymorphism enables you to:
a. program in the general.
b. program in the specific.
c. absorb attributes and behavior from previous classes.
d. hide information from the user.
Section 10.2 Polymorphism Examples
10.2 Q1: For which of the following would polymorphism not provide a clean
solution?
a. A billing program where there is a variety of client types that are billed with
different fee structures.
b. A maintenance log program where data for a variety of types of machines is
collected and maintenance schedules are produced for each machine based on the
data collected.
c. A program to compute a 5% savings account interest for a variety of clients.
d. An IRS program that maintains information on a variety of taxpayers and
determines who to audit based on criteria for classes of taxpayers.
10.2 Q2: Polymorphism allows for specifics to be dealt with during:
a. execution.
b. compilation.
c. programming.
d. debugging.
Java How to Program, 11/e Multiple Choice Test Bank 2 of 11
Section 10.3 Demonstrating Polymorphic
Behavior
10.3 Q1: Which statement best describes the relationship between superclass and
subclass types?
a. A subclass reference cannot be assigned to a superclass variable and a superclass
reference cannot be assigned to a subclass variable.
b. A subclass reference can be assigned to a superclass variable and a superclass
reference can be assigned to a subclass variable.
c. A superclass reference can be assigned to a subclass variable, but a subclass
reference cannot be assigned to a superclass variable.
d. A subclass reference can be assigned to a superclass variable, but a superclass
reference cannot be assigned to a subclass variable.
Section 10.4 Abstract Classes and Methods
10.4 Q1: A(n) class cannot be instantiated.
a. final.
b. concrete.
c. abstract.
d. polymorphic.
10.4 Q2: Non-abstract classes are called ________.
a. real classes.
b. instance classes.
c. implementable classes.
d. concrete classes.
Section 10.5 Case Study: Payroll System
Using Polymorphism
10.5 Q1: It is a UML convention to denote the name of an abstract class in
________.
a. bold.
Java How to Program, 11/e Multiple Choice Test Bank 3 of 11
b. italics.
c. a diamond.
d. there is no convention of the UML to denote abstract classes—they are listed just
as any other class.
10.5 Q2: If the superclass contains only abstract method declarations, the
superclass is used for ________.
a. implementation inheritance.
b. interface inheritance.
c. Both.
d. Neither.
Section 10.5.1 Abstract Superclass Employee
10.5.1 Q1: Which of the following could be used to declare abstract method
method1 in abstract class Class1 (method1 returns an int and takes no arguments)?
a. public int method1();
b. public int abstract method1();
c. public abstract int method1();
d. public int nonfinal method1();
10.5.1 Q2: Which of the following statements about abstract superclasses is true?
a. abstract superclasses may contain data.
b. abstract superclasses may not contain implementations of methods.
c. abstract superclasses must declare all methods as abstract.
d. abstract superclasses must declare all data members not given values as
abstract.
Section 10.5.2 Concrete Subclass
SalariedEmployee
10.5.2 Q1: Consider the abstract superclass below:
public abstract class Foo {
private int a;
public int b;
Java How to Program, 11/e Multiple Choice Test Bank 4 of 11
public Foo(int aVal, int bVal) {
a = aVal;
b = bVal;
}
public abstract int calculate();
}
Any concrete subclass that extends class Foo:
a. Must implement a method called calculate.
b. Will not be able to access the instance variable a.
c. Neither (a) nor (b).
d. Both (a) and (b).
Section 10.5.3 Concrete Subclass HourlyEmployee
(No questions.)
Section 10.5.4 Concrete Subclass
CommisionEmployee
(No Questions.)
Section 10.5.5 Indirect Concrete Subclass
BasePlusCommissionEmployee
10.5.5 Q1: Consider classes A, B and C, where A is an abstract superclass, B is a
concrete class that inherits from A and C is a concrete class that inherits from B. Class
A declares abstract method originalMethod, implemented in class B. Which of the
following statements is true of class C?
a. Method originalMethod cannot be overridden in class C—once it has been
implemented in concrete class B, it is implicitly final.
b. Method originalMethod must be overridden in class C, or a compilation error will
occur.
c. If method originalMethod is not overridden in class C but is called by an object of
class C, an error occurs.
d. None of the above.
Java How to Program, 11/e Multiple Choice Test Bank 5 of 11
Section 10.5.6 Polymorphic Processing, Operator
instanceof and Downcasting
10.5.6 Q1: When a superclass variable refers to a subclass object and a method is
called on that object, the proper implementation is determined at execution time.
What is the process of determining the correct method to call?
a. early binding.
b. non-binding.
c. on-time binding.
d. late binding.
10.5.6 Q2: Every object in Java knows its own class and can access this information
through method .
a. getClass.
b. getInformation.
c. objectClass.
d. objectInformation.
Section 10.6 Allowed Assignments Between
Superclass and Subclass Variables
10.6 Q1: Assigning a subclass reference to a superclass variable is safe ________.
a. because the subclass object has an object of its superclass.
b. because the subclass object is an object of its superclass.
c. only when the superclass is abstract.
d. only when the superclass is concrete.
Section 10.7 final Methods and Classes
10.7 Q1: Classes and methods are declared final for all but the following reasons:
a. final methods allow inlining the code.
b. final methods and classes prevent further inheritance.
c. final methods are static.
d. final methods can improve performance.
10.7 Q2: All of the following methods are implicitly final except:
a. a method in an abstract class.
b. a private method.
c. a method declared in a final class.
d. static method.
10.7 Q3: Declaring a method final means:
a. it will prepare the object for garbage collection.
b. it cannot be accessed from outside its class.
c. it cannot be overloaded.
d. it cannot be overridden.
Section 10.8 A Deeper Explanation of Issues
with Calling Methods from Constructors
10.8 Q1: Which of the following is false?
a. You should not call overridable methods from constructors—when creating a
subclass object, this could lead to an overridden method being called before the
subclass object is fully initialized.
b. It’s OK to any of a class’s methods from its constructors.
c. When you construct a subclass object, its constructor first calls one of the direct
superclass’s constructors. If the superclass constructor calls an overridable method,
the subclass’s version of that method will be called by the superclass constructor.
d. It’s acceptable to call a static method from a constructor.
Section 10.9 Creating and Using Interfaces
10.9 Q1: In Java SE 7 and earlier, an interface may contain:
a. private static data and public abstract methods.
b. only public abstract methods.
c. public static final data and public abstract methods.
d. private static data and public final methods.
10.9 Q2: Which of the following does not complete the sentence correctly?
An interface .
a. forces classes that implement it to declare all the abstract interface methods.
Java How to Program, 11/e Multiple Choice Test Bank 7 of 11
b. can be used in place of an abstract class when there is no default implementation
to inherit.
c. is declared in a file by itself and is saved in a file with the same name as the
interface followed by the .java extension.
d. can be instantiated.
Section 10.9.1 Developing a Payable Hierarchy
10.9.1 Q1: The UML distinguishes an interface from other classes by placing the
word “interface” in above the interface name.
a. italics.
b. carets.
c. guillemets.
d. bold.
Section 10.9.2 Interface Payable
10.9.2 Q1: Interfaces can have methods.
a. 0
b. 1
c. 2
d. any number of
Section 10.9.3 Class Invoice
10.9.3 Q1: Which keyword is used to specify that a class will define the methods of
an interface?
a. uses
b. implements
c. defines
d. extends
10.9.3 Q2: Which of the following is not possible?
a. A class that implements two interfaces.
b. A class that inherits from two classes.
c. A class that inherits from one class, and implements an interface.
Java How to Program, 11/e Multiple Choice Test Bank 8 of 11
d. All of the above are possible.
Section 10.9.4 Modifying Class Employee to
Implement Interface Payable
10.9.4 Q1: A class that implements an interface but does not declare all of the
interface’s methods must be declared ________.
a. public.
b. interface.
c. abstract.
d. final.
10.9.4 Q2: Which of the following statements is false?
a. An advantage of inheritance over interfaces is that only inheritance provides the is-a
relationship.
b. Objects of any subclass of a class that implements an interface can also be thought of
as objects of that interface type.
c. When a method parameter is declared with a subclass or interface type, the method
processes the object passed as an argument polymorphically.
d. All objects have the methods of class Object.
Section 10.9.5 Using Interface Payable to Process
Invoices and Employees Polymorphically
10.9.6 Q1: Which of the following statements is false?
a. References to interface types do not have access to method toString.
b. Method toString can be invoked implicitly on any object.
c. With inheritance, classes and their inherited classes tend to be very similar.
d. Dramatically different classes can often meaningfully implement the same interface.
Section 10.9.6 Some Common Interfaces of the Java
API
10.9.7: Q1: Which interface is used to identify classes whose objects can be written
to or read from some type of storage or transmitted across a network?
a. Comparable
b. Runnable
c. AutoCloseable
d. Serializable
10.9.7: Q2: Which interface is specifically intended to be implemented by classes
that can be used with the try-with-resources statement?
a. Comparable
b. Runnable
c. AutoCloseable
d. Serializable
Section 10.10 Java SE 8 Interface Enhancements
(No questions.)
Section 10.10.1 default Interface Methods
10.10.1 Q1: Which of the following statements is false?
a. In Java SE 8, an interface may declare default methods—that is, public methods
with concrete implementations that specify how an operation should be performed.
b. When a class implements an interface, the class receives the interface’s default
concrete implementations if it does not override them.
c. When you enhance an existing interface with default methods—any class that
implemented the original interface will break.
d. With default methods, you can declare common method implementations in
interfaces (rather than abstract classes), which gives you more flexibility in designing
your classes.
Section 10.10.2 static Interface Methods
10.10.2 Q1: Which of the following statements is false?
Java How to Program, 11/e Multiple Choice Test Bank 10 of 11
a. Prior to Java SE 8, it was common to associate with an interface a class containing
static helper methods for working with objects that implemented the interface.
b. Class Collections contains many static helper methods for working with objects
that implement interfaces Collection, List, Set and more.
c. Collections method sort can sort objects of any class that implements interface
List.
d. With non–static interface methods, helper methods can now be declared directly
in interfaces rather than in separate classes.
Section 10.10.3 Functional Interfaces
10.10.3 Q1: Which of the following statements is false?
a. As of Java SE 8, any interface containing only one method is known as a
functional interface.
b. There are many functional interfaces throughout the Java APIs.
c. Functional interfaces are used extensively with Java SE 8’s new lambda
capabilities.
d. Anonymous methods provide a shorthand notation for creating lambdas.
Section 10.11 Java SE 9 private Interface Methods
10.11 Q1: Which of the following statements is false?
a. A class’s private helper methods may be called only by the class’s other
methods
b. You cannot declare helper methods in interfaces.
c. An interface’s private instance methods can be called directly (i.e., without an
object reference) only by the interface’s other instance methods.
d. An interface’s private static methods can be called by any of the interface’s
instance or static methods.
Java How to Program, 11/e Multiple Choice Test Bank 11 of 11
Section 10.12 private Constructors
10.12 Q1: Which of the following statements is false?
a. You cannot prevent client code from creating objects of a class.
b. One common use of a private constructor is sharing initialization code among a
class’s other constructors.
c. Another common use of private constructors is to force client code to use so-
called “factory methods” to create objects.
d. A factory method is a public static method that creates and initializes an
object of a specified type (possibly of the same class), then returns a reference to it.
Section 10.13 Program to an Interface, Not an
Implementation
10.12 Q1: Which of the following statements is false?
a. Java allows a class to implement multiple interfaces in addition to extending one
class.
b. Classes declared with implementation inheritance are tightly coupled.
c. Classes declared with interface inheritance are tightly coupled.
d. An interface also may extend one or more other interfaces.