Chapter 11 Inheritance Flashcards
What is the relationship called in which one object is a specialized version of another object?
a. parent-child
b. is a
c. node-to-node
d. class-subclass
is a
Chapter 11 Q (page# 552)
When one object is a specialized version of another object, there is an “is a” relationship between them.
When an “is a” relationship exists between objects, it means that the specialized object has all the characteristics of the general object, plus additional characteristics that make it special.
Given the following line of code, in a UML diagram, what would the open arrowhead point to?
class Celery(Vegetable):
a. Celery
b. Celery(Vegetable)
c. class
d. Vegetable
Vegetable
Chapter 11 Q (page# 560)
You show inheritance in an UML diagram by drawing a line with an open arrowhead from the the subclass to the superclass. (The arrowhead points to the superclass).
A subclass may not override any method other than the _ _ init_ _ method. True or False?
False
Chapter 11 Q (page# 552)
You can think of the subclass an an extended version of the superclass. The subclass inherits attributes and methods from the superclass without any of them having to be rewritten. Furthermore, new attributes and methods may be added to the subclass, and that what makes it a specialized version.
An “is a” relationship exists between a grasshopper and a bumblebee.
True or False?
False
Chapter 11 Q (page# 552)
When one object is a specialized version of another object, there is an “is a” relationship between them. For example, a grasshopper is an insect.
When an “is a “ relationship exists between objects, it means that the specialized object has all the characteristics of the general object, plus additional characteristics that make it special.
Each subclass has a method named _ _ init_ _ that overrides the superclass's _ _init_ _ method. True or False?
True
Chapter 11 Q
In an inheritance relationship, what is a specialized class called?
a. a superclass
b. an object
c. an instance
d. a subclass
a subclass
Chapter 11 Q (page# 552) Inheritance involves a superclass and a subclass. The superclass is the general class and the subclass is the specialized class. Superclasses are also called base classes, and subclasses are also called derived classes.
___ allows a new class to inherit members of the class it extends.
a. Methods
b. Inheritance
c. Attributes
d. Encapsulation
Inheritance
Chapter 11 Q
Inheritance allows a new class to extend an existing class. The new class inherits the members of the class it extends.
Which of the following is the correct syntax for defining a class, table, which inherits from the furniture class?
a, class table.furniture:
b. class table (furniture):
c. class furniture(table):
d. class furniture(table):
class table (furniture):
Chapter 11 Q
In here, we are defining a class named table, and inherits from the furniture class. The table class is the subclass, and the furniture class is the superclass.
class Subclass(Superclass):
New attributes and methods may be added to a subclass.
True or False
True
Chapter 11 Q
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. 3 mutator, 3 accessor
b. 4 mutator, 4 accessor
c. 3 mutator, 4 accessor
d. 1 mutator, 1 accessor
3 mutator, 3 accessor
Chapter 11 Q