Gaddis Python 2e Chapter 12
Download file with the answers
Gaddis Python 2e Chapter 12
1 file(s) 120.80 KB
If you are not a member register here to download this file
Chapter Twelve
MULTIPLE CHOICE
1. _____ allows a new class to inherit the members of the class it extends.
a. Encapsulation
b. Domain
c. Methods
d. Inheritance
ANS: D
2. What concept involves a superclass and a subclass?
a. Polymorphism
b. Inheritance
c. Encapsulation
d. Methods
ANS: B
3. 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
4. What does a subclass inherit from a superclass?
a. Instances and attributes
b. Data and methods
c. Methods and instances
d. Attributes and methods
ANS: D
5. In the following line of code, what is the name of the subclass?
class Rose(Flower):
a. Rose
b. Flower
c. Either
d. Incorrect code
ANS: A
6. In the following line of code, what is the name of the base class?
class Male(Human):
a. Male
b. Human
c. Either
d. Incorrect code
ANS: B
7. In a UML diagram, what does the open arrowhead point to?
a. Superclass
b. Subclass
c. Object
d. Method
ANS: A
8. Examine the following piece of code:
class Potato (Vegetable):
In a UML diagram, what would the open arrowhead point to?
a. Potato
b. Vegetable
c. class
d. Potato(Vegetable)
ANS: B
9. 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
10. In an inheritance relationship, what is a specialized class called?
a. Superclass
b. Subclass
c. Object
d. Method
ANS: B
11. Of the two classes Cola and Soda, which would most likely be the subclass?
a. Cola
b. Soda
c. Both
d. Either
ANS: A
12. Which method can you use to determine whether an object is an instance of a class?
a. isinstance
b. isclass
c. isobject
d. isinheritance
ANS: A
13. Which of the following is the correct syntax for defining a class dining which inherits from class furniture?
a. class furniture(dining)
b. class dining(furniture)
c. class furniture(dining):
d. class dining(furniture):
ANS: D
14. Base classes are also called _____.
a. superclasses
b. derived
c. subclasses
d. classes
ANS: A
15. What is the relationship called in which one object is a specialized version of another object?
a. Parent-child
b. Node
c. Is a
d. Class
ANS: C
TRUE/FALSE
1. True/False: New attributes and methods may be added to a subclass.
ANS: T
2. True/False: It is not possible to indicate inheritance in a UML diagram.
ANS: F
3. True/False: Each subclass has a method named __init__ that overrides the superclass’s __init__.
ANS: T
4. True/False: When a class inherits another class, it is required to use all the data attributes and methods of the superclass.
ANS: F
5. True/False: An ‘is a’ relationship exists between a grasshopper and a bumblebee.
ANS: F
6. True/False: In a UML diagram depicting inheritance, you only write the name of the subclass.
ANS: F
7. True/False: A subclass may not override any method other than the __init__ method.
ANS: F
8. True/False: Polymorphism works on any two class methods that have the same name.
ANS: T
9. True/False: One of the ingredients of polymorphic behavior is the ability to define a method in a subclass, and then define a method with the same name in a superclass.
ANS: F
10. True/False: A superclass inherits attributes and methods from its subclasses without any of them having to be rewritten.
ANS: F
FILL IN THE BLANK
1. _______________ allows subclasses to have methods with the same names as methods in their superclasses.
ANS: Polymorphism
2. The _______________ function determines whether an object is an instance of a specific class, or an instance of a subclass of that class.
ANS: isinstance
3. A subclass is also called a(n) _______________ class.
ANS: derived
4. _______________ is used to create an ‘is a’ relationship among classes.
ANS: Inheritance
5. When a subclass method has the same name as a superclass method, it is often said that the subclass method _______________ the superclass method.
ANS: overrides
6. In an inheritance relationship, the extended class is called the _______________.
ANS: subclass
7. Superclasses are also called _______________ classes.
ANS: base
8. New attributes and methods may be added to a subclass, which makes it a(n) _______________ version of the superclass.
ANS: specialized
9. In an inheritance relationship, a television is a(n) _______________ of the electronics class.
ANS: subclass
10. The term _______________ refers to an object’s ability to take different forms.
ANS: polymorphism
Leave a reply