Deck 12: Father Was a Rectangle: Inheritance and Object-Oriented Design
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/32
Play
Full screen (f)
Deck 12: Father Was a Rectangle: Inheritance and Object-Oriented Design
1
The ____ relationship describes two objects where one object is a more specific instance of the other.
A) OF-A
B) HAS-A
C) IS-A
D) BELONGS-TO
A) OF-A
B) HAS-A
C) IS-A
D) BELONGS-TO
C
2
The ______ relationship describes two objects where one object uses another object.
A) OF-A
B) HAS-A
C) IS-A
D) BELONGS-TO
A) OF-A
B) HAS-A
C) IS-A
D) BELONGS-TO
B
3
In a hierarchy diagram, the most ____ object is at the top.
A) general
B) specific
C) complicated
D) simple
A) general
B) specific
C) complicated
D) simple
A
4
In inheritance, the more general class is called the ____ class.
A) child
B) superclass
C) model
D) subclass
A) child
B) superclass
C) model
D) subclass
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
5
When two classes are connected by an IS-A link, what do we call a class that inherits from a higher class in the inheritance hierarchy?
A) Subclass
B) Method
C) Instance variable
D) Superclass
A) Subclass
B) Method
C) Instance variable
D) Superclass
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
6
In an expanded object hierarchy for shapes, which of the following would be the most specific (or least general) class?
A) GeometricObject
B) Shape
C) Ellipse
D) Square
A) GeometricObject
B) Shape
C) Ellipse
D) Square
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
7
Case Study 1:
1. myCanvas = Canvas (800, 600)
2. myLine = Line(Point (-100, -100), Point (100, 100))
3. myCanvas.draw(myLine)
-Refer to the session in the accompanying Case Study 1. What can be inferred about the Canvas class?
A) It will have a draw method.
B) It will be constructed with two Points.
C) It does not have a constructor.
D) It will have three instance variables.
1. myCanvas = Canvas (800, 600)
2. myLine = Line(Point (-100, -100), Point (100, 100))
3. myCanvas.draw(myLine)
-Refer to the session in the accompanying Case Study 1. What can be inferred about the Canvas class?
A) It will have a draw method.
B) It will be constructed with two Points.
C) It does not have a constructor.
D) It will have three instance variables.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
8
Case Study 1:
1. myCanvas = Canvas (800, 600)
2. myLine = Line(Point (-100, -100), Point (100, 100))
3. myCanvas.draw(myLine)
-Refer to the session in the accompanying Case Study 1. What can be inferred about the Point class?
A) It has a method draw.
B) It is required to create a Canvas.
C) It has at least two instance variables.
D) It is a subclass.
1. myCanvas = Canvas (800, 600)
2. myLine = Line(Point (-100, -100), Point (100, 100))
3. myCanvas.draw(myLine)
-Refer to the session in the accompanying Case Study 1. What can be inferred about the Point class?
A) It has a method draw.
B) It is required to create a Canvas.
C) It has at least two instance variables.
D) It is a subclass.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
9
The ____ method of the screen is used to define the width and height.
A) __init__
B) setup
C) move
D) setWidth
A) __init__
B) setup
C) move
D) setWidth
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
10
What is the name of the property that allows Python to call the right method of an object depending on the type of object referenced by a superclass?
A) Polymorphism
B) Inheritance
C) Abstraction
D) Mutation
A) Polymorphism
B) Inheritance
C) Abstraction
D) Mutation
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
11
In the object hierarchy presented in the text, GeometricObject is a(n) ____ class.
A) sub
B) specific
C) abstract
D) parameter
A) sub
B) specific
C) abstract
D) parameter
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
12
How do you call the constructor of a superclass within a subclass?
A) __init()__
B) super().__init__()
C) super()
D) parent().init()
A) __init()__
B) super().__init__()
C) super()
D) parent().init()
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
13
How do you designate that B is a parent class of A?
A) class A extends B
B) class A[B]
C) class A(B)
D) class A of B:
A) class A extends B
B) class A[B]
C) class A(B)
D) class A of B:
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
14
Case Study 2:
1. >>> myLine
2. &It;draw.Line object at 0x106f6b0>
3. >>> myCanvas
4. &It;draw.Canvas instance at 0x1070328>
5. >>> isinstance(myLine, Line)
6. ??????
-Refer to the session in the accompanying Case Study 2. What is output on line 6?
A) True
B) False
C) Line
D) myLine
1. >>> myLine
2. &It;draw.Line object at 0x106f6b0>
3. >>> myCanvas
4. &It;draw.Canvas instance at 0x1070328>
5. >>> isinstance(myLine, Line)
6. ??????
-Refer to the session in the accompanying Case Study 2. What is output on line 6?
A) True
B) False
C) Line
D) myLine
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
15
What variable holds the name of the parent of a class?
A) __parent__
B) __self___
C) __super__
D) __bases__
A) __parent__
B) __self___
C) __super__
D) __bases__
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
16
When designing a project, it is a good idea to begin by making a list of the different kinds of objects involved and the relationships between those objects.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
17
The class where the IS-A link originates is called the superclass.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
18
It is good programming practice to write all the code for a large program at once and then to test it.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
19
The constructor method is always named __init__.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
20
The __dict__ variable is a dictionary that keeps track of the methods defined for the class.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
21
Match each definition with its term.
-A more general class.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
-A more general class.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
22
Match each definition with its term.
-Provides us with one place to define instance variables and methods used by subclasses.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
-Provides us with one place to define instance variables and methods used by subclasses.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
23
Match each definition with its term.
-A more specific class.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
-A more specific class.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
24
Match each definition with its term.
-The class from which all classes inherit.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
-The class from which all classes inherit.
A) Superclass
B) Abstract class
C) Subclass
D) The object class
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
25
What is the difference between an IS-A relationship and a HAS-A relationship?
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
26
What is inheritance? As an example, explain how Shape and a Rectangle are related.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
27
Explain the benefits of using inheritance when creating a program that uses a variety of shapes with common characteristics.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
28
Explain how the Canvas draw method presented in your text makes use of the _draw method in GeometricObject.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
29
How does a Python object reference the class of which it is an instance?
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
30
Explain how Python evaluates the expression myLine.getWidth().
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
31
Describe the visibleObject instance variable that was added to the Canvas class presented in your text. How does this variable help improve drawing?
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
32
Describe the drawAll method of the Canvas class presented in your text.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck