Python4e Gaddis ch11 Drake
Python4e Gaddis ch11 Drake
Chapter 11 Inheritance
TRUE/FALSE
ANS: T
2. One problem with using a UML diagram is that there is no way to indicate inheritance.
ANS: F
3. When a class inherits another class, it is required to use all the data attributes and methods of the
superclass.
ANS: F
4. Polymorphism works on any two class methods that have the same name.
ANS: T
5. A superclass inherits attributes and methods from its subclasses without any of them having to be
rewritten.
ANS: F
6. A subclass may not override any method other than the __init__ method.
ANS: F
7. Each subclass has a method named __init__ that overrides the superclass's __init__ method.
ANS: T
8. In a UML diagram depicting inheritance, you only need to write the name of the subclass.
ANS: F
ANS: F
ANS: T
MULTIPLE CHOICE
2. What gives a program the ability to call the correct method depending on the type of object that is used
to call it?
a. Polymorphism
b. Inheritance
c. Encapsulation
d. Methods
ANS: A
5. When there are several classes that have many common data attributes, it is better to write a(n)
__________ to hold all the general data.
a. superclass
b. subclass
c. object
d. method
ANS: A
8. What is the relationshop called in which one object is a specialized version of another object?
a. parent-child
b. node-to-node
c. is a
d. class-subclass
ANS: C
9. __________ has the ability to define a method in a subclass and then define a method with the same
name in a superclass.
a. Inheritance
b. Encapsulation
c. Polymorphism
d. the 'is a' relationship
ANS: C
10. In the following line of code, what is the name of the subclass?
class Rose(Flower):
a. Rose
b. Flower
c. Rose(Flower)
d. None of these
ANS: A
11. In the following line of code, what is the name of the base class?
class Python(Course):
a. Python
b. Course
c. Python(Course)
d. None of these
ANS: B
12. Given the following line of code, in a UML diagram, what would the open arrowhead point to?
class Celery(Vegetable):
a. Celery
b. Vegetable
c. class
d. Celery(Vegetable)
ANS: B
13. Of the two classes, Cherry and Flavor, which would most likely be the subclass?
a. Cherry
b. Flavor
c. either one
d. neither; these are inappropriate class or subclass names
ANS: A
14. Which method can you use to determine whether an object is an instance of a class?
a. isinstance
b. isclass
c. isobject
d. issubclass
ANS: A
15. Which of the following is the correct syntax for defining a class, table, which inherits from the
furniture class?
a. class furniture[table]:
b. class table.furniture:
c. class furniture(table):
d. class table(furniture):
ANS: D
16. Given the following beginning of a class definition for a superclass named clock, how many
accessor and mutator methods will be needed to complete the class definition?
class clock:
def __init__(self, shape, color, price):
self._shape = shape
self.color = color
self.price = price
a. 1 mutator, 1 accessor
b. 3 mutator, 4 accessor
c. 3 mutator, 3 accessor
d. 4 mutator, 5 accessor
ANS: C
COMPLETION
1. __________ allows subclasses to have methods with the same names as methods in their superclasses.
ANS: Polymorphism
2. The __________ function determines whether or not an object is an instance of a specific class or an
instance of a subclass of that class.
ANS: isinstance
ANS: derived
4. A superclass is also called a(n) __________ class.
ANS: base
5. When a subclass method has the same name as a superclass method, the subclass method __________
the superclass method.
ANS: overrides
ANS: subclass
7. New attributes and methods may be added to a subclass which makes it a(n) __________ version of
the superclass.
ANS: specialized
8. In an inheritance relationship, a minivan can be thought of as a(n) ___________ of the vehicles class.
ANS: polymorphism
10. In a UML diagram, a line with an open arrowhead from a subclass to a superclass indicates
___________.
ANS: inheritance