程序代写代做代考 python Starting Out with Python 4e (Gaddis)
Starting Out with Python 4e (Gaddis)
Chapter 11 Inheritance
TRUE/FALSE
1. New attributes and methods may be added to a subclass.
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
9. An “is a” relationship exists between a grasshopper and a bumblebee.
ANS: F
10. An “is a” relationship exists between a wrench and a tool.
ANS: T
MULTIPLE CHOICE
1. __________ allows a new class to inherit members of the class it extends.
a.
Encapsulation
b.
Attributes
c.
Methods
d.
Inheritance
ANS: D
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
3. What does a subclass inherit from a superclass?
a.
instances and attributes
b.
objects and methods
c.
methods and instances
d.
attributes and methods
ANS: D
4. In a UML diagram, what does the open arrowhead point to?
a.
the superclass
b.
the subclass
c.
the object
d.
a method
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
6. In an inheritance relationship, what is a specialized class called?
a.
a superclass
b.
a subclass
c.
an object
d.
an instance
ANS: B
7. Base classes are also called
a.
superclasses
b.
derived classes
c.
subclasses
d.
class instances
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
3. A subclass is also called a(n) __________ class.
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
6. In an inheritance relationship, the extended class is called the __________.
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: subclass, derived class
9. The term ___________ refers to an object’s ability to take different forms.
ANS: polymorphism
10. In a UML diagram, a line with an open arrowhead from a subclass to a superclass indicates ___________.
ANS: inheritance