Professional Documents
Culture Documents
Test Bank For Fundamentals of Python Data Structures 2nd Edition Kenneth Lambert
Test Bank For Fundamentals of Python Data Structures 2nd Edition Kenneth Lambert
2. When a class is customized using inheritance, the two classes should have a similar interface.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
3. When you use inheritance to customize a class, the existing and new class have identical behavior.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
5. To begin creating a subclass, copy the parent class's file and delete the methods that will not change.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
6. To ensure that inheritance occurs, you need to place the name of the subclass in parentheses of the class
header.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
7. The __init__ method in the parent class is automatically called by a subclass of the parent class.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 2
Name: Class: Date:
8. When calling the __init__ method from a subclass, you need to include the self argument.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
9. To distinguish a method in the parent class from a method with the same name in a subclass, prefix the
method name with self.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
11. By using inheritance to create new classes, you increase code redundancy.
a. True
b. False
ANSWER: False
Copyright Cengage Learning. Powered by Cognero. Page 3
Name: Class: Date:
12. An abstract class captures the common features and behavior of a set of related classes.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
14. A concrete class is often a subclass of an abstract class and is used to create objects in client applications.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 4
Name: Class: Date:
15. An instance variable is considered redundant if two different classes use it and it refers to a different type of
data structure in each class.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
16. An instance variable that refers to an integer in two different related classes is a likely candidate to be
moved to an abstract class.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
17. A set of methods that could be used on other data structures besides the one they were created for could be
used in a general abstract class.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
18. When looking at a hierarchy of abstract classes, the classes trend from the more specific to the more general
going from the top to the bottom of the hierarchy.
Copyright Cengage Learning. Powered by Cognero. Page 5
Name: Class: Date:
19. The implementations of the __str__ and __eq__ methods in the AbstractCollection class can be used in both
unordered and linear collections.
a. True
b. False
ANSWER: False
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
20. A class that uses lists can use the methods defined in the AbstractCollection class.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
21. The __eq__ method in the AbstractCollection class compares pairs of items in two collections.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
Copyright Cengage Learning. Powered by Cognero. Page 6
Name: Class: Date:
23. Programming languages such as Java include a collection framework more extensive than that of Python.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: A Professional-Quality Framework of Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
24. When a programmer calls the iter function on a collection, the collection's iterator object is returned.
a. True
b. False
ANSWER: True
POINTS: 1
DIFFICULTY: Easy
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: True / False
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:20 PM
27. Which of the following is true about the sorted bag collection compared to the regular bag collection?
a. the add method is identical in both
b. the __init__ method is identical in both
c. the sorted bag's in operator runs in linear time
d. the items in a sorted bag must be of the same type
ANSWER: d
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
28. When considering the ArrayBag class and the ArraySortedBag class, which of the following is true?
Copyright Cengage Learning. Powered by Cognero. Page 8
Name: Class: Date:
29. How is creating a subclass of an existing class different from copying the code from the existing class to a
new file?
a. delete all the methods that don't have to change
b. you don't need an __init__ method
c. the name of the subclass is in parentheses of the class header
d. no methods need be created or modified
ANSWER: a
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
30. Which of the following is NOT a step in using inheritance to create a subclass?
a. delete the methods that do not change
b. duplicate redundant instance variables
c. modify the code for methods that change
d. add any new methods
ANSWER: b
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 9
Name: Class: Date:
32. In the ArraySortedBag class, why must the self argument be passed to the __init__ method of ArrayBag?
a. to ensure the add method in ArraySortedBag is called if a source collection is specified
b. to ensure that ArraySortedBag calls the correct __init__ method
c. to ensure that ArrayBag calls its own __init__ method
d. to ensure the add method in ArrayBag is called if a source collection is specified
ANSWER: a
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
33. What method is called when the in operator is used on a sorted bag?
a. __iter__
b. __contains__
c. __init__
d. add
ANSWER: b
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
34. In which situation is a search unnecessary when performing the add method on a sorted bag?
a. when the bag is full
b. when the new item is less than the last item
c. when the new item is greater than the first item
d. when the bag is empty
ANSWER: d
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
35. The following code is part of the add method in the ArraySortedBag class. What is the missing code?
a. add.self(item)
b. ArrayBag.add(item)
c. ArrayBag.add(self, item)
d. add.ArrayBag(self, item)
ANSWER: c
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
36. Which operator, when used with two bags, causes Python to run the __add__ method?
a. =
b. *
c. +
d. %
ANSWER: c
POINTS: 1
DIFFICULTY: Easy
Copyright Cengage Learning. Powered by Cognero. Page 11
Name: Class: Date:
38. What is a class called when the purpose of it is to eliminate redundant methods in other classes?
a. concrete class
b. abstract class
c. subclass
d. child class
ANSWER: b
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
40. Under which circumstance can an instance variable be moved to an abstract class?
a. when it refers to the same type of data structure
b. when it is unique to a particular concrete class
c. when different data structure types are referenced by the variable
d. when it directly modifies the underlying data structure
ANSWER: a
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
41. Which of the following is true about the three bag classes (LinkedBag, ArrayBag, ArraySortedBag)?
a. they are abstract classes
b. they implement the bag interface
c. the are all superclasses
d. LinkedBag is a subclass of ArraySortedBag
ANSWER: b
POINTS: 1
DIFFICULTY: Easy
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
42. When implementing the __init__ method in the AbstractBag class, what task should you leave out because
it is the responsibility of the subclasses?
a. setting the self.size variable to 0
b. adding items from the source collection
c. initializing the self.items variable
d. checking if a source collection exists
43. When you finish writing the abstract class, what must the subclasses do to use it?
a. reference the abstract class in their __init__ method.
b. copy the code to the subclass file
c. nothing, the abstract class is automatically included in the subclass
d. import the abstract class
ANSWER: d
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
44. In the constructor for the ArrayBag class shown below, what is the missing code?
a. items.add(self)
b. self.items = Array(ArrayBag.DEFAULT_CAPACITY)
c. self.items = ArrayBag.add(sourceCollection)
d. add.items(self, sourceCollection)
ANSWER: b
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Abstract Classes to Eliminate Redundant Code
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
46. In the case of the AbstractCollection class, which of the following methods should NOT be included in this
class?
a. add
b. isEmpty
c. __len__
d. count
ANSWER: a
POINTS: 1
DIFFICULTY: Moderate
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
47. When creating the AbstractCollection class, which methods must you modify to provide default behavior?
a. __len__ and count
b. __str__ and __eq__
c. isEmpty and add
d. __init__ and __len__
ANSWER: b
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
48. When a programmer calls the next function on an iterator object, what happens if there is no current item in
the sequence?
a. the previous item is returned
b. the compiler generates an error
c. a StopIteration exception is raised
d. the None item is returned
ANSWER: c
POINTS: 1
DIFFICULTY: Easy
REFERENCES: An Abstract Class for All Collections
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
49. In the following code for the ArrayBag class __contains__ method, what is the missing code?
a. right = midPoint + 1
b. left = midPoint - 1
c. right = left + 1
d. left = midPoint + 1
ANSWER: d
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM
Copyright Cengage Learning. Powered by Cognero. Page 16
Test Bank for Fundamentals of Python: Data Structures 2nd Edition Kenneth Lambert
50. In the following code for the __add__ method in the ArraySortedBag class, what is the missing code?
a. result = result + 1
b. item.add(result)
c. result.add(item)
d. add.item(result)
ANSWER: c
POINTS: 1
DIFFICULTY: Difficult
REFERENCES: Using Inheritance to Customize an Existing Class
QUESTION TYPE: Multiple Choice
HAS VARIABLES: False
DATE CREATED: 9/2/2018 6:19 PM
DATE MODIFIED: 9/2/2018 6:19 PM