Python Programming - Inheritance

Exercise : Inheritance - General Questions
  • Inheritance - General Questions
11.
What is the primary purpose of the isinstance() function?
To check if an object is an instance of a specific class
To create a new instance of a class
To access class attributes directly
To call a method of the superclass
Answer: Option
Explanation:
The isinstance() function is used to determine if an object is an instance of a specified class or a tuple of classes.

12.
In Python, what is the significance of the __str__() method in a class?
To create a new instance of the class
To define the class attributes
To provide a human-readable string representation of the object
To access superclass attributes directly
Answer: Option
Explanation:
The __str__() method is used to define a human-readable string representation of an object and is called by the str() function.

13.
How can you achieve method overloading?
By defining multiple methods with the same name but different parameters
By using the @overload decorator
By explicitly specifying the data type of method parameters
Method overloading is not supported in Python
Answer: Option
Explanation:
Python does not support method overloading in the traditional sense, as methods with the same name in a class will override each other.

14.
What is a potential issue with using multiple inheritance?
Difficulty in determining method resolution order
Inability to define class attributes
Naming conflicts in class methods
Automatic resolution of method conflicts
Answer: Option
Explanation:
Multiple inheritance in Python may lead to the diamond problem, resulting in difficulty determining the method resolution order and potential ambiguity.

15.
In Python, what happens when a subclass defines a method with the same name as a method in its superclass?
The superclass method is automatically overridden
The subclass method is ignored
An error occurs, and the program crashes
The subclass method overrides the superclass method
Answer: Option
Explanation:
In Python, if a subclass defines a method with the same name as a method in its superclass, the subclass method will override the superclass method.