OOP - Python Questions (In Class)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What must be included in the subclass init method as the first statement?

A call to the superclass init method

The Python initialization method is the same as any other method, except it has a special name, __init__.

True

The one difference between methods and normal functions is that all methods have one required argument, called self.

True

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

True

__str__ is a special method that is called automatically when string conversion is performed.

True

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

class inherits from a superclass

Which function must be used to call a method of a superclass?

super

Consider the following code segment: class Fruit : def __init__(self, name) : . . . class Apple : def __init__self(self, name) : . . .

x = Apple("McIntosh")

Which of the following is true regarding subclasses?

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

What does the subclass inherit from a superclass?

Data and behaviour

A superclass inherits data and behavior from a subclass.

False

A superclass inherits only behavior from a subclass.

False

If the method __str__ is not defined in the class of x, str(x) issues an error.

False

Polymorphism allows a programmer to use a subclass object in place of a superclass object.

False

Python does not allow multiple inheritance

False

The major difference between these two methods is that __new__ handles object initialization and __init__ handles object creation.

False

The syntax for multiple inheritance looks like a parameter list in the class definition, except they are separated by semi colon.

False

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

False

Consider: class Vehicle: What is Vehicle's superclass?

Object

A class that represents a more specific entity in an inheritance hierarchy is called a/an _______.

Subclass

A class that represents the most general entity in an inheritance hierarchy is called a/an ______.

Superclass

Identify the subclass and superclass in the following code segment: class ChoiceQuestion(Question) : def __init__(self) : . . .

The subclass is ChoiceQuestion. The superclass is Question.

A mixin is meant to be inherited by some other class to provide extra functionality.

True

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

True

By using super() keyword, we are able to address diamond problem in inheritance.

True

By using super() keyword, we are employing "depth-first, left-to right" rule in inheritance.

True

Composition defines a "has a" relationship.

True

Diamond inheritance describes the problem of setting up the base class twice.

True

Inheritance defines a "is-a" relationship

True

Multiple inheritance is when a subclass that inherits from more than one parent class is able to access functionality from both of them.

True

Polymorphism allows manipulating objects that share a set of tasks and execute them in different ways.

True

Assume that you are creating a new Python class named Vehicle, as shown below: class Vehicle : . . . What is Vehicle's superclass?

object

Which class is the direct or indirect superclass of every class in Python?

object


संबंधित स्टडी सेट्स

Accounting Chapter 11, ACCT 5312 (Ch. 8-11) Exam 3

View Set

CoursePoint Final Exam Practice Test

View Set

Week 2 quiz questions - Diabetes

View Set