Chapter 11 Inheritance Flashcards

1
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
A subclass may not override any method other than the _ _ init_ _ method.
True or False?
A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

An “is a” relationship exists between a grasshopper and a bumblebee.
True or False?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Each subclass has a method named _ _ init_ _ that overrides the superclass's _ _init_ _ method.
True or False?
A

True

Chapter 11 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In an inheritance relationship, what is a specialized class called?

a. a superclass
b. an object
c. an instance
d. a subclass

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

___ allows a new class to inherit members of the class it extends.

a. Methods
b. Inheritance
c. Attributes
d. Encapsulation

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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):

A

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):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

New attributes and methods may be added to a subclass.

True or False

A

True

Chapter 11 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
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

A

3 mutator, 3 accessor

Chapter 11 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly