Python Programming - Inheritance

Exercise : Inheritance - General Questions
  • Inheritance - General Questions
31.
In Python, what is the purpose of the __call__() method in a class?
To call a method of the superclass
To create a new instance of the class
To make an instance of the class callable
To access class attributes directly
Answer: Option
Explanation:
The __call__() method is called when an instance of a class is used as a function, allowing instances to be callable.

32.
What is the purpose of the __eq__() method in Python classes?
To define class attributes
To create a new instance of the class
To customize the equality comparison between instances
To access superclass attributes directly
Answer: Option
Explanation:
The __eq__() method is used to customize the equality comparison between instances of a class.

33.
How can you prevent a class in Python from being inherited by other classes?
By using the @final decorator
By defining all methods as private
By declaring the class as sealed
By not providing a superclass for the class
Answer: Option
Explanation:
In Python, a class can be prevented from being inherited by using the @final decorator.

34.
What is the purpose of the __len__() method in Python classes?
To define class attributes
To create a new instance of the class
To customize the behavior of the len() function for instances of the class
To access superclass attributes directly
Answer: Option
Explanation:
The __len__() method is used to customize the behavior of the len() function for instances of a class.

35.
What is the purpose of the @abstractmethod decorator?
To create a new instance of the class
To define a method that must be implemented by subclasses
To access class attributes directly
To override a method in the superclass
Answer: Option
Explanation:
The @abstractmethod decorator is used to define an abstract method in a class, which must be implemented by any concrete subclasses.