Exercise: Python

Questions for: Inheritance

What is a potential issue with using multiple inheritance?
A:
Difficulty in determining method resolution order
B:
Inability to define class attributes
C:
Naming conflicts in class methods
D:
Automatic resolution of method conflicts
Answer: A
Multiple inheritance in Python may lead to the diamond problem, resulting in difficulty determining the method resolution order and potential ambiguity.
How can you achieve method overloading?
A:
By defining multiple methods with the same name but different parameters
B:
By using the @overload decorator
C:
By explicitly specifying the data type of method parameters
D:
Method overloading is not supported in Python
Answer: D
Python does not support method overloading in the traditional sense, as methods with the same name in a class will override each other.
In Python, what is the significance of the __str__() method in a class?
A:
To create a new instance of the class
B:
To define the class attributes
C:
To provide a human-readable string representation of the object
D:
To access superclass attributes directly
Answer: C
The __str__() method is used to define a human-readable string representation of an object and is called by the str() function.
What is the primary purpose of the isinstance() function?
A:
To check if an object is an instance of a specific class
B:
To create a new instance of a class
C:
To access class attributes directly
D:
To call a method of the superclass
Answer: A
The isinstance() function is used to determine if an object is an instance of a specified class or a tuple of classes.
In Python, what is the purpose of the super(type, obj) function?
A:
To call the superclass constructor
B:
To create a new instance of the subclass
C:
To access class attributes directly
D:
To explicitly specify the superclass
Answer: A
The super(type, obj) function is used to call the constructor of the superclass, providing a way to initialize the superclass when working with multiple inheritance.
Ad Slot (Above Pagination)
Quiz