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

Question 10

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 3

0 / 1 point

You have been asked to write a program that involves animals. Some animals are herbivores. Within this program, any animal that is not a herbivore is a carnivore. Which set of class definitions is most appropriate for this program?

Question options:

class Animal :

. . .

class Herbivore(Animal) :

. . .

class Carnivore(Herbivore) :

. . .

class Animal :

. . .

class Carnivore(Animal) :

. . .

class Herbivore(Carnivore) :

. . .

class Animal :

. . .

class Herbivore(Animal) :

. . .

class Carnivore(Animal) :

. . .

class Animal(Herbivore, Carnivore) :

. . .

class Herbivore :

. . .

class Carnivore :

. . .

Question 4

0 / 1 point

Consider the following classes:

class Vehicle :

def __init__(self, name) :

self._name = name

class LandVehicle(Vehicle) :

def __init__(self, numWheels) :

super().__init__("Land Vehicle")

____________________

def getWheels(self) :

return self._numWheels

What statement should be placed in the blank to complete the constructor for LandVehicle?

Question options:

_numWheels = numWheels

self._numWheels = numWheels

super()._numWheels = numWheels

super().__init__(numWheels)

Question 5

0 / 1 point

A class name inside parentheses in the class header indicates that the:

Question options:

class inherits from a default class

class inherits from a superclass

class inherits from a subclass

class inherits from the object class

Question 6

0 / 1 point

You are creating a Motorcycle class which is supposed to inherit from the Vehicle class. Which of the following class declaration statements will accomplish this?

Question options:

class Motorcycle(self) :

class Motorcycle extends Vehicle :

class Motorcycle is Vehicle :

class Motorcycle(Vehicle) :

Question 7

0 / 1 point

What object oriented programming concept can often be used to eliminate explicit type tests?

Question options:

Class variables

Encapsulation

Functions

Polymorphism

Question 8

0 / 1 point

Insert the missing code in the following code fragment. This fragment is intended to call the Vehicle class's method.

class Vehicle :

def setVehicleClass(self, numberAxles) :

...

class Motorcycle(Vehicle) :

def __init__(self) :

__________________

harley = Motorcycle()

Question options:

self.setVehicleClass(2)

setVehicleClass(2)

Motorcycle.setVehicleClass(2)

Vehicle.setVehicleClass(2)

Question 9

0 / 1 point

Consider the following program:

class Dinosaur :

def __init__(self, name="dinosaur") :

self._name = name

def display(self) :

print(self._name)

class Triceratops(Dinosaur) :

def __init__(self) :

super().__init__("triceratops")

x = Triceratops()

x.display()

What is displayed when it executes?

Question options:

dinosaur

triceratops

Nothing is displayed

The program crashes with a method not implemented error

Question 10

0 / 1 point

Which of the following statements about inheritance is correct?

Question options:

You can always use a superclass object in place of a subclass object.

You can always use a subclass object in place of a superclass object.

A superclass inherits data and behavior from a subclass.

A superclass inherits only behavior from a subclass.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!