Week 11 Flashcards
New attributes and methods may be added to a subclass.
True
One problem with using a UML diagram is that there is no way to indicate inheritance.
false lol the whole point of the diagram is to show inheritance
When a class inherits another class, it is required to use all the data attributes and methods of the superclass.
False
Polymorphism works on any two class methods that have the same name.
True
A superclass inherits attributes and methods from its subclasses without any of them having to be rewritten.
False
A subclass may not override any method other than the __init__ method.
False
Each subclass has a method named __init__ that overrides the superclass’s __init__ method.
True
In a UML diagram depicting inheritance, you only need to write the name of the subclass.
False
An “is a” relationship exists between a grasshopper and a bumblebee.
False
An “is a” relationship exists between a wrench and a tool.
__________ allows a new class to inherit members of the class it extends.
a. Encapsulation
b. Attributes
c. Methods
d. Inheritance
inheritance
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
a. Polymorphism
What does a subclass inherit from a superclass?
a. instances and attributes
b. objects and methods
c. methods and instances
d. attributes and methods
attributes and methods
In a UML diagram, what does the open arrowhead point to?
a. the superclass
b. the subclass
c. the object
d. a method
The superclass
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
a. superclass
In an inheritance relationship, what is a specialized class called?
a. a superclass
b. a subclass
c. an object
d. an instance
a subclass
Base classes are also called
a. superclasses
b. derived classes
c. subclasses
d. class instances
a. superclasses
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
c. is a
__________ 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
Polymorphism
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
rose
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
course
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)
vegetable
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
Cherry
Which method can you use to determine whether an object is an instance of a class?
a. isinstance
b. isclass
c. isobject
d. issubclass
isinstance
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):
class table(furniture):
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
3 mutator, 3 accessor
__________ allows subclasses to have methods with the same names as methods in their superclasses.
Polymorphism
The __________ function determines whether or not an object is an instance of a specific class or an instance of a subclass of that class.
isinstance
A subclass is also called a(n) __________ class.
derived class
A superclass is also called a(n) __________ class.
base
When a subclass method has the same name as a superclass method, the subclass method __________ the superclass method.
overrides
In an inheritance relationship, the extended class is called the __________.
Superclass
New attributes and methods may be added to a subclass which makes it a(n) __________ version of the superclass.
True
In an inheritance relationship, a minivan can be thought of as a(n) ___________ of the vehicles class.
Subclass, derived class
The term ___________ refers to an object’s ability to take different forms.
Polymorphism