CIS 41A Chapter 10

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following is true regarding subclasses? 1. A subclass inherits methods from its superclass but not instance variables. 2. A subclass inherits instance variables from its superclass but not methods. 3. A subclass inherits methods and instance variables from its superclass. 4. A subclass does not inherit methods or instance variables from its superclass.

A subclass inherits methods and instance variables from its superclass

What does the subclass inherit from a superclass? 1. Data and behavior 2. Only behaviors 3. Only data 4. Nothing

Data and behavior

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 = Dinosaur() x.display() What is displayed when it executes? 1. |dinosaur| 2. |triceratops| 3. Nothing is displayed 4. The program crashes with a method not implemented error

Dinosaur

What is the name of the superclass in the following code segment? class Triceratops(Dinosaur) : def eat(self, what) : . . . 1. |Dinosaur| 2. |eat| 3. |Triceratops| 4. |what|

Dinosaur

What is dynamic method lookup? 1. Dynamic method lookup is the process of determining, at runtime, what method will be invoked based on the type of the object. 2. 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|). 3. Dynamic method lookup is the process of finding a method in a superclass when it has not been overridden in a subclass. 4. Dynamic method lookup is the process of overriding a method in a subclass that has already been defined in the superclass.

Dynamic method lookup is the process of determining, at runtime, what method will be invoked based on the type of the object.

Identify the list of superclasses from the list of pairs below: Manager, Employee GraduateStudent, Student BankAccount, CheckingAccount Vehicle, Minivan 1. Employee, Student, BankAccount, Vehicle 2. Manager, GraduateStudent, CheckingAccount, Minivan 3. Employee, Student, CheckingAccount, Minivan 4. Manager, GraduateStudent, BankAccount, Vehicle

Employee, Student, BankAccount, Vechile

Which statement is correct about the following code segment: class Pizza : . . . class Food(Pizza) : . . . 1. |Pizza| is a subclass of |Food| 2. |Food| is a subclass of |Pizza| 3. |Food| and |Pizza| do not have a superclass / subclass relationship 4. The code segment does not allow one to determine what the superclass / subclass relationship is between the classes

Food is a subclass of pizza

Consider classes |Oranges, Pears, Apples, Fruit|. Which should be the superclass? 1. |Oranges| 2. |Pears| 3. |Apples| 4. |Fruit|

Fruit

Given the following hierarchy, which class is considered the base class? class GeometricShape : . . . class Line(GeometricShape) : . . . class Rectangle(GeometricShape) : . . . lass Square(Rectangle) : . . . 1. |Square| 2. |Rectangle| 3. |Line| 4. |GeometricShape|

GeometricShape

Which class is the direct or indirect superclass of every class in Python? 1. |default| 2. |None| 3. |object| 4. |super|

object

What term describes the process of manipulating objects that share a set of tasks, even though the tasks are executed in different ways? 1. Inheritance 2. Polymorphism 3. Hierarchy 4. Overriding

polymorphism

What statement is commonly used to prevent a class's user from invoking an abstract method? 1. |raise NotImplementedError| 2. |return NotImplementedError| 3. |self.NotImplementedError| 4. |set NotImplementedError|

raise NotImplementedError

Consider the following code segment: class Employee : def __init__(self, name) : . . . def getSalary(self) : . . . . . . class Programmer(Employee) : def __init__(self, name) : . . . def writeProgram(self) : . . . Which of the following code segments is *not* legal? 1.e = Employee("Bob") print(e.getSalary()) 2. e = Employee("Bob") e.writeProgram() 3. p = Programmer("Bob") print(p.getSalary()) 4. p = Programmer("Bob") p.writeProgram()

s

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|? 1. |_numWheels = numWheels| 2. |self._numWheels = numWheels| 3. |super()._numWheels = numWheels| 4. |super().__init__(numWheels)|

self._numWheels = numWheels

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() 1. self.setVehicleClass(2) 2. setVehicleClass(2) 3. Motorcycle.setVehicleClass(2) 4. Vehicle.setVehicleClass(2)

self.setVehicleClass(2)

Insert the missing code in the following code fragment. This fragment is intended to call the |Vessel| class's method. class Vessel : def setVesselClass(self, vesselLength) : ... class JetSki(Vessel) : def __init__(self) : __________________ mySki = JetSki() 1. JetSki.setVessel(12) 2. setVesselClass(12) 3.self.setVesselClass(12) 4. Vessel.setVessel(12)

self.setVesselClass(12)

Assuming the |Rectangle| class is already designed with a constructor |__init__(self, x, y, width, height)|, which code snippet creates a square in the top left corner? 1. square = Rectangle(0, 0, 100, 100) 2. square = Rectangle(100, 100, 0, 0) 3. square = Rectangle(0, 0, 0, 0) 4. square = Rectangle(100, 100, 100, 100)

square = Rectangle(0, 0, 100, 100)

When you call a superclass method from a subclass method (without overriding the method), what keyword must replace the |self| reference? 1. super 2. base 3. reference 4. def

super

Which function must be used to call a method of a superclass? 1. |__init__| 2. |parent| 3. |super| 4. |self|

super

Assume that you have a class |Apple| which is a subclass of |Fruit|. Which statement can be used in |Apple|'s constructor to invoke |Fruit|'s constructor? 1. |__init__()| 2. |Apple().__init__()| 3. |Fruit().__init__()| 4. |super().__init__()|

super().__init__()

Consider the following class definitions: class Dinosaur : . . . def eat(self, what) : . . . class Triceratops(Dinosaur) : . . . ____________________ . . . What statement should be placed in the blank to override the implementation of the |eat| method? 1. |allow eat(self, what) :| 2. |def eat(self, what) :| 3. |new eat(self, what) :| 4. |override eat(self, what) :|

2. |def eat(self, what) :|

Consider the following class definitions: class Vehicle : . . . def __init__(self) : self._numAxles = 0 . . . def setAxles(self, num) : self._numAxles = num . . . class Motorcycle(Vehicle) : def __init__(self) : super().__init__() ________________________ Which statement should be placed in the blank so that all motorcycles have 2 axles? 1. |setAxles(2)| 2. |self.setAxles(2)| 3. |super().setAxles(2)| 4. |Vehicle.setAxles(2)|

3. |super().setAxles(2)

What must be included in the subclass constructor as the first statement|?| 1. Initialization of all instance variables 2. A call to the superclass constructor 3. A call to the accessor and mutator methods 4. A call to the subclass constructor

A call to the superclass constructor

Which of the following statements about superclasses and subclasses is true? 1. A superclass is larger than its subclass. 2. A superclass inherits from a subclass. 3. A superclass extends a subclass. 4. A subclass extends a superclass.

A subclass extends a superclass

Which of the following is true regarding subclasses? 1. A subclass has access to private instance variables of its superclass. 2. A subclass does not have access to public instance variables of its superclass. 3. A subclass must specify the implicit parameter to use methods inherited from its superclass. 4. A subclass has no access to private instance variables of its superclass.

A subclass has no access to private instance variables of its superclass

Which of the following is true regarding subclasses? 1. A subclass that inherits methods from its superclass may not override the methods. 2. A subclass that inherits instance variables from its superclass may not declare additional instance variables. 3. A subclass may inherit methods or instance variables from its superclass but not both. 4. A subclass may inherit methods and instance variables from its superclass, and may also implement its own methods and declare its own instance variables.

A subclass may inherit methods and instance variables from its superclass, and may also implement its own methods and declare its own instance variables

A class from which you cannot create objects is called a/an ____. 1. Concrete class. 2. Non-inheritable class. 3. Superclass. 4. Abstract class.

Abstract class

Which of the following statements is true? 1. A programmer cannot create an instance a concrete class. 2. A programmer cannot create an instance of an abstract class. 3. Abstract classes are designed to force programmers to create subclasses. 4. Calling any method defined in an abstract class will raise a |NotImplementedError| exception.

Abstract classes are designed to force programmers to create subclasses.

Which of the following statements about abstract methods is true? 1. An abstract method has a name and parameters, but its implementation is not specified. 2. An abstract method has parameters and is fully implemented, but it has no defined name. 3. An abstract method has a name and is fully implemented, but it has no parameters. 4. An abstract method has only a name, but it implementation is not specified and it has no parameters.

An abstract method has a name and parameters, but its implementation is not specified.

Consider the following code segment: class Animal : # The body of the class has been omitted class Dinosaur(Animal) : # The body of the class has been omitted class Triceratops(Dinosaur) : # The body of the class has been omitted class Pterodactyl(Dinosaur) : # The body of the class has been omitted Which class is at the root of the inheritance hierarchy? 1. Animal 2. Dinosaur 3. Pterodactyl 4. Triceratops

Animal

What is the name of the subclass in the following code segment? class Apple(Fruit) : def getCalories(self) : . . . 1. |Apple| 2. |Fruit| 3. |getCalories| 4. |self|

Apple

Consider the following class definitions: class Fruit : . . . def getColor(self) : . . . class Apple(Fruit) : . . . Which statement is most correct? 1. Apple cannot have a method named |getColor| 2. Apple inherits the |getColor| method from |Fruit| 3. Apple must override the |getColor| method from |Fruit| 4. Apple must call the |getColor| method from |Fruit|

Apple inherits the getColor method from Fruit

What would be the inhertiance relationships between classes |Apples, Pears,| and |Fruit?| 1. |Apples| inherit from |Pears| 2. |Apples| and |Pears| inherit from |Fruit| 3. |Fruit| inherits from |Apples| and |Pears| 4. |Pears| inherits from |Apples|

Apples and Pears inherit from Fruit

Consider the following classes: class Dinosaur : . . . class Triceratops(Dinosaur) : . . . class Pterodactyl(Dinosaur) : . . . Which of the following statements is correct? 1. Methods in |Dinosaur| can call methods in |Pterodactyl| 2. Methods in |Dinosaur| can call methods in |Triceratops| 3. Methods in |Triceratops| can call methods in |Dinosaur| 4. Methods in |Triceratops| can call methods in |Pterodactyl|

Methods in |Triceratops| can call methods in |Dinosaur|

What type of method is used to extend or replace the functionality of the superclass method? 1. Concrete method 2. Abstract method 3. Overriding method 4. Constructor method

Overriding Method

What object oriented programming concept can often be used to eliminate explicit type tests? 1. Class variables 2. Encapsulation 3. Functions 4. Polymorphism

Polymorphism

What is the role of polymorphism? 1. Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. 2. Polymorphism allows a programmer to use a subclass object in place of a superclass object. 3. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. 4. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work.

Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways.

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()) 1. |Auto| 2. |Sedan| 3. |Vehicle| 4. A runtime error occurs

Sedan

A class that represents a more specific entity in an inheritance hierarchy is called a/an _______. 1. Default class 2. Superclass 3. Subclass 4. Inheritance class

Subclass

A class that represents the most general entity in an inheritance hierarchy is called a/an ______. 1. Default class 2. Superclass 3. Subclass 4. Inheritance class

Superclass

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() . . . 1. The return statement cannot include string concatenation 2. The |Physician| class cannot contain a method named |getName| 3. The body of the |getName| method in |Physician| contains a logic error 4. |Physician| is not a subclass of |Person|

The body of the getName method in Physician contains a logic error

Consider the following code snippet: anEmployee = new Programmer() anEmployee.increaseSalary(2500) If the |Programmer| class inherits from the |Employee| class, and both classes have an implementation of the |increaseSalary| method with the same set of parameters, which statement is correct? 1. An additional line of code must be added to the snippet shown previously to specify which method will execute. 2. It is not possible to determine which class's method will be executed without seeing the complete class definitions. 3. The |increaseSalary| method of the |Employee| class will be executed. 4. The |increaseSalary| method of the |Programmer| class will be executed.

The increaseSalary method of the Programmer class will be executed

Consider the following code snippet: aVehicle = new Auto() aVehicle.moveForward(200) If the |Auto| class inherits from the |Vehicle| class, and both classes have an implementation of the |moveForward| method with the same set of parameters, which statement is correct? 1. The |moveForward| method of the |Auto| class will be executed. 2. The |moveForward| method of the |Vehicle| class will be executed. 3. You must specify in the code which class's |moveForward| method is to be used. 4. It is not possible to determine which class's method is called.

The moveForward method of the Auto class will be executed.

Identify the subclass and superclass in the following code segment: class ChoiceQuestion(Question) : def __init__(self) : . . . 1. The subclass is |Question|. The superclass is |ChoiceQuestion|. 2. The subclass is |ChoiceQuestion|. The superclass is |Question|. 3. The subclass is |init|. The superclass is |self|. 4. The subclass is |ChoiceQuestion|. The superclass is |object|.

The subclass is |ChoiceQuestion|. The superclass is |Question|.

What must a subclass do to modify a private superclass instance variable? 1. The subclass must simply use the name of the superclass instance variable. 2. The subclass must declare its own instance variable with the same name as the superclass instance variable. 3. The subclass must use a public method of the superclass (if it exists) to update the superclass's private instance variable. 4. The subclass must have its own public method to update the superclass's private instance variable.

The subclass must use a public method of the superclass (if it exists) to update the superclass's private instance variable.

Consider the following code snippet: class BankAccount : . . . def deposit(self, amount) : self._transactionCount = self._transactionCount + 1 super().deposit(amount) Which of the following statements is correct? 1. This method will call itself. 2. This method calls a public method in its subclass. 3. This method calls a private method in its superclass 4. This method calls a public method in its superclass

This method calls a public method in its subclass.

What is the purpose of using an inheritance hierarchy? 1. To share common code among the classes 2. To create objects from concrete classes 3. To create objects from abstract classes 4. To create objects using constructors

To share common code among the classes

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? 1. |dinosaur| 2. |triceratops| 3. Nothing is displayed 4. The program crashes with a method not implemented error

Triceratops

You are creating a class inheritance hierarchy about motor vehicles that will contain classes named |Vehicle|, |Auto|, and |Motorcycle|. Which of the following statements is correct? 1. |Vehicle| should be the subclass, while |Auto|, and |Motorcycle| should be the default classes 2. |Vehicle| should be the subclass, while |Auto|, and |Motorcycle| should be the superclasses 3. |Vehicle| should be the default class, while |Auto|, and |Motorcycle| should be the subclasses 4. |Vehicle| should be the superclass, while |Auto|, and |Motorcycle| should be the subclasses

Vehicle should be the superclass, while Auto and Motorcycle should be the subclasses

Which of the following statements about inheritance is correct? 1. You can always use a superclass object in place of a subclass object. 2. You can always use a subclass object in place of a superclass object. 3. A superclass inherits data and behavior from a subclass. 4. A superclass inherits only behavior from a subclass

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

What is the substitution principle? 1. A subclass inherits data and behavior from a superclass 2. You can create an object from a concrete class, but not from an abstract class. 3. You can always use a superclass object when a subclass object is expected 4. You can always use a subclass object when a superclass object is expected

You can always use a subclass object when a superclass object is expected

If a class has an abstract method, which of the following statements is NOT true? 1. You cannot inherit from this class. 2. You cannot construct an object from this class. 3. You can construct an object from this class. 4. All non-abstract subclasses of this class must implement this method.

You can construct an object from this class.

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 . . . 1. |_x, _y, _width, _height, _fill, _outline| 2. |_x, _y, _width, _height| 3. |_x, _y| 4. |_width, _height|

_width, _height

Assuming that a class called |Oval| is already defined with a constructor |__init__(self, x, y, width, height)|, how could this be used to make a circle? 1. Use one value for |x| and |y| 2. Pass the same value for each |width| and |height| 3. Use one value for |x|, |y|, |width|, and |height| 4. It is not possible to make a circle using the |Oval| class

a

Assuming the |Rectangle| class is already designed with a constructor |__init__(self, x, y, width, height)|, which code snippet creates a square in the middle of a frame with FRAME_WIDTH = 400, FRAME_HEIGHT = 600? 1. square = Rectangle(FRAME_WIDTH/2, FRAME_HEIGHT/2, 100, 100) 2. square = Rectangle(FRAME_WIDTH, FRAME_HEIGHT, 100, 100) 3. square = Rectangle(FRAME_WIDTH-50, FRAME_HEIGHT - 50, 100, 100) 4. square = Rectangle(FRAME_WIDTH/2 - 50, FRAME_HEIGHT/2 - 50, 100, 100)

a

To compute the salary of a manager, the program must first get the salary of the underlying |Employee| object and then add a bonus. class Manager(Employee) : . . . def getSalary(self) : _________________________ return base + self._bonus Which statement correctly completes the code: 1. |base = self.getSalary()| 2. |base = super().getSalary()| 3. |base = super().self.getSalary()| 4. |base = super(self.getSalary()|)

a

Which of the following statements is true? 1. A method that is overridden in a subclass can perform a task that is totally different from the task performed by the same method in the superclass. 2. A method that is overridden in a subclass cannot invoke the method in the superclass with the same name. 3. A method that is overridden in a subclass must extend the functionality of the superclass by invoking the superclass method. 4. Every method in a subclass must override a superclass method.

a

Consider the following class: class Pet : def makeSound(self) : raise NotImplementedError This class is said to be: 1. an abstract class 2. a dynamic class 3. an iterator class 4. a method class

an abstract class

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? 1. class Animal : . . . class Herbivore(Animal) : . . . class Carnivore(Herbivore) : . . . 2. class Animal : . . . class Carnivore(Animal) : . . . class Herbivore(Carnivore) : . . . 3. class Animal : . . . class Herbivore(Animal) : . . . class Carnivore(Animal) : . . . 4. class Animal(Herbivore, Carnivore) : . . . class Herbivore : . . . class Carnivore : . . .

class Animal : . . . class Herbivore(Animal) : . . .class Carnivore(Animal) : . . .

Which set of classes represents the relationship that all circles are ovals? 1. class Circle(Oval) : . . . 2. class Oval(Circle) : . . . 3. class Circle : . . . class Oval : . . . 4. class Shape : . . . class Circle(Shape) : . . . class Oval(Shape) : . . .

class Circle(Oval)

Which of the following statements indicates that |ClassA| is a superclass of |ClassB|? 1. |class ClassB(ClassA) :| 2. |class ClassA(ClassB) : | 3. |class ClassB extends ClassA : | 4. |class ClassA extends ClassB : |

class ClassB(ClassA)

Which of the following class declaration statements will create a class |Dog| that is a subclass of |Pet|? 1. class Dog is Pet : 2. class Dog(Pet) : 3. class Dog extends Pet : 4. class Dog(self) :

class Dog(pet)

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? 1. class Motorcycle(self) : 2.class Motorcycle extends Vehicle : 3. class Motorcycle is Vehicle : 4. class Motorcycle(Vehicle) :

class Motorcycle(Vehicle)

You are creating a |Pen| class that will be a subclass of a |WritingImplement| class. Which statement accomplishes this goal? 1. |class Pen(WritingImplement) :| 2. |class WritingImplement(Pen) :| 3. |subclass Pen(WritingImplement) :| 4. |subclass WritingImplement(Pen) :|

class Pen(WritingImplment)

Which set of classes is poorly designed? 1. class Pet : . . . class Cat(Pet) : . . . class Dog(Pet) : . . . 2. class Pizza : . . . class Food(Pizza) : . . . class Apple(Food) : . . . 3. class Vehicle : . . . class Car(Vehicle) : . . . class HatchBack(Car) : . . . 4.class Pizza : . . . class Employee : . . . class Textbook : . . .

class Pizza : . . . class Employee : . . . class Textbook : . . .

Which group of classes is poorly designed? 1. class Vegetable : . . . class Dog : . . . 2. class Pet : . . . class Dog(Pet) : . . . 3. class Fruit : . . . class Vegetable : . . . 4.class Dog : . . . class Cat(Dog) : . . .

class Vegetable : . . . class Dog : . . .

A class name inside parentheses in the class header indicates that the: 1. class inherits from a default class 2. class inherits from a superclass 3. class inherits from a subclass 4. class inherits from the |object| class

class inherits from a superclass

What term is used for a class that does not include any abstract methods? 1. Cement class 2. Concrete class 3. Iron class 4. Steel class

concrete class

Consider a class hierarchy for representing shapes. The hierarchy includes a |GeometricShape| base class that defines and manages all of characteristics and operations that are common to all shapes. A portion of this class is shown below: class GeometricShape : def __init__(self, x, y): self._x = x self._y = y self._fill = None self._outline = "black" def setColor(self, color) : self._fill = color self._outline = color def getX(self) : return self._x def setPosition(self, newx, newy) : self._x = newx self._y = newy def draw(self, canvas) : raise NotImplementedError Which method must be overridden in a subclass of |GeometricShape|? 1. |draw| 2. |getX| 3. |setColor| 4. |setPosition|

draw

Which method is being overridden in the following code segment? class Dinosaur : def __init__(self) : . . . def getName(self): . . . def draw(self) : . . . class Triceratops(Dinosaur) : def __init__(self) : . . . def draw(self) : . . . 1. |Dinosaur| 2. |draw| 3. |getName| 4. |Triceratops|

draw

If a method in a subclass carries out the action of the superclass method and also does some additional work then the method in the subclass is said to ____________________ the functionality of the superclass method. 1. extend 2. interpolate 3. reference 4. replace

extend

Which method is being overridden in the following code segment? class Car : def __init__(self, make, model, color) : . . . def getMake(self) : . . . def getModel(self) : . . . def getColor(self) : . . . class Apple : def __init__(self, color) : . . . def getColor(self) : . . . 1. |getMake| 2. |getModel| 3. |getColor| 4. No method is being overridden in this code segment

getColor

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 1. getWidth(), getHeight() 2. getX(), getY(), getWidth(), getHeight() 3. getX(), getY(), setColor() 4. getX(), getY(), getWidth(), getHeight()

getX(), getY(), getWidth(), getHeight()

Consider the following class hierarchy: class Vehicle : def __init__(self, type) : self._type = type class LandVehicle(Vehicle) : def __init__(self, type) : super().__init__(type) class Auto(Vehicle) : def __init__(self, type) : ____________________________ Complete the code in the |Auto| class constructor to store the type data. 1. super(type) 2. super().super().__init__(type) 3. super().__init__(type) 4. This cannot be done unless the |Auto| class declares an instance variable named |type|.

super().__init__(type)

Consider the following code segment: class Fruit : . . . def getName(self) : . . . class Apple(Fruit) : . . . def getName(self) : . . . Which statement is most correct? 1. The |Apple| class overrides the |Fruit| class 2. The |Apple| class overrides the |getName| method 3. The |Fruit| class overrides the |Apple| class 4. The |Fruit| class overrides the |getName| method

the apple class overrides the fruit class

Consider the following code snippet: class Vehicle : . . . def setVehicleAttributes(self) : . . . class Auto(Vehicle) : . . . def setVehicleAttributes(self) . . . Which of the following statements is correct? 1. The subclass is overloading a superclass method. 2. The subclass is overriding a superclass method. 3. This subclass is referencing a superclass method. 4. The subclass is shadowing a superclass method.

the subclass is overriding a superclass method

A subclass object can always be used when a superclass object is expected. This fact is referred to as: 1. generalized interoperability 2. method overriding 3. the replacement policy 4. the substitution principle

the substitution principle

To override a superclass method in a subclass, the subclass method must: 1. use a different method name than the superclass method. 2. use the same method name as the superclass method. 3. use the same list of parameter variables as the superclass method. 4. use a different list of parameter variables than the superclass method.

use the same method name as the superclass method

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? 1. |x = Fruit()| 2. |x = Fruit("Apple")| 3. |x = Apple()| 4. |x = Apple("McIntosh")|

x = Apple("McIntosh")

Assume that you are creating a new Python class named |Vehicle|, as shown below: class Vehicle : . . . What is |Vehicle|'s superclass? 1. |dict| 2. |None| 3. |object| 4. |set|

|object|


Ensembles d'études connexes

Real Estate Brokerage: Unit Exams

View Set

Power Engineering 4th Class Chapter 82

View Set

Pos psych - Book notes Ch. 7 (pg. 267 - 301)

View Set

Google Data Analytics - Process Data from Dirty to Clean - Course 4

View Set

The Rowlatt Acts and the Amritsar Massacre

View Set

Lesson 2 Estructura 2.2 Forming questions in Spanish Audio

View Set