Question: Given the following hierarchy, which class is considered the base class? class GeometricShape : . . . class Line(GeometricShape) : . . . class Rectangle(GeometricShape)
Given the following hierarchy, which class is considered the base class?
class GeometricShape :
. . .
class Line(GeometricShape) :
. . .
class Rectangle(GeometricShape) :
. . .
class Square(Rectangle) :
. . .
Question options:
| Square | |||
| Rectangle | |||
| Line | |||
| GeometricShape | |||
| Question 6 | 0 / 1 point | ||
Consider the following code segment:
class Fruit :
def __init__(self, name) :
. . .
class Apple :
def __init__self(self, name) :
. . .
Which statement successfully creates a new Apple object?
Question options:
| x = Fruit() | |||
| x = Fruit("Apple") | |||
| x = Apple() | |||
| x = Apple("McIntosh") | |||
| Question 7 | 0 / 1 point | ||
What does the subclass inherit from a superclass?
Question options:
| Data and behavior | |||
| Only behaviors | |||
| Only data | |||
| Nothing | |||
| Question 9 | 0 / 1 point | ||
Consider the following code snippet:
class Vehicle :
. . .
def setVehicleAttributes(self) :
. . .
class Auto(Vehicle) :
. . .
def setVehicleAttributes(self)
. . .
Which of the following statements is correct?
Question options:
| The subclass is overloading a superclass method. | |||
| The subclass is overriding a superclass method. | |||
| This subclass is referencing a superclass method. | |||
| The subclass is shadowing a superclass method. | |||
| Question 10 | 0 / 1 point | ||
What type of method is used to extend or replace the functionality of the superclass method?
Question options:
| Concrete method | |
| Abstract method | |
| Overriding method | |
| Constructor method |
Given the code snippet below, what instance variables does an object of the Rectangle class have?
class GeometricShape :
def __init__(self, x, y) :
self._x = x
self._y = y
self._fill = None
self._outline = "blue"
. . .
class Rectangle(GeometricShape) :
def __init__(self, x, y, width, height) :
super().__init__(x, y)
self._width = width
self._height = height
. . .
Question options:
| _x, _y, _width, _height, _fill, _outline | |||
| _x, _y, _width, _height | |||
| _x, _y | |||
| _width, _height | |||
| Question 3 | 0 / 1 point | ||
If a class has an abstract method, which of the following statements is NOT true?
Question options:
| You cannot inherit from this class. | |
| You cannot construct an object from this class. | |
| You can construct an object from this class. | |
| All non-abstract subclasses of this class must implement this method. |
What is dynamic method lookup?
Question options:
| Dynamic method lookup is the process of determining, at runtime, what method will be invoked based on the type of the object. | |||
| Dynamic method lookup is the process of finding a method amongst a collection of classes that do not have a common superclass (other than object). | |||
| Dynamic method lookup is the process of finding a method in a superclass when it has not been overridden in a subclass. | |||
| Dynamic method lookup is the process of overriding a method in a subclass that has already been defined in the superclass. | |||
| Question 7 | 0 / 1 point | ||
Given the code snippet below, what methods does an object of the Rectangle class have?
class GeometricShape :
def __init__(self, x, y) :
self._x = x
self._y = y
self._fill = None
self._outline = "blue"
. . .
def getX(self) :
return self._x
def getY(self) :
return self._y
class Rectangle(GeometricShape) :
def __init__(self, x, y, width, height) :
super().__init__(x, y)
self._width = width
self._height = height
def getWidth(self) :
return self._width
def getHeight(self) :
return self._height
Question options:
| getWidth(), getHeight() | |||
| getX(), getY(), getWidth(), getHeight() | |||
| getX(), getY(), setColor() | |||
| getX(), getY(), getWidth(), getHeight() | |||
| Question 8 | 0 / 1 point | ||
What is wrong with the following classes?
class Person :
. . .
def getName(self) :
return self._name
. . .
class Physician(Person) :
. . .
def getName(self) :
return "Dr. " + self.getName()
. . .
Question options:
| The return statement cannot include string concatenation | |||
| The Physician class cannot contain a method named getName | |||
| The body of the getName method in Physician contains a logic error | |||
| Physician is not a subclass of Person | |||
| Question 10 | 0 / 1 point | ||
Consider the following classes:
class Vehicle :
def __init__(self, type) :
self._type = type
def getType(self) :
return self._type
class LandVehicle(Vehicle) :
def __init__(self, type) :
super().__init__(type)
class Auto(LandVehicle) :
def __init__(self, type) :
super().__init__(type)
What is displayed by the following code segment?
x = Auto("Sedan")
print(x.getType())
Question options:
| Auto | |
| Sedan | |
| Vehicle | |
| A runtime error occurs |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
