Python Programming - Inheritance

Exercise : Inheritance - General Questions
  • Inheritance - General Questions
21.
In Python, what is the purpose of the __init_subclass__() method?
To initialize the attributes of a subclass
To create a new instance of a subclass
To initialize attributes common to all subclasses
To customize the creation of subclasses
Answer: Option
Explanation:
The __init_subclass__() method is called when a new subclass is created, allowing customization of the creation process.

22.
How does Python handle circular dependencies in the context of inheritance?
It automatically resolves circular dependencies
It raises an error, and the program crashes
It requires explicit handling using additional syntax
Circular dependencies are not allowed in Python
Answer: Option
Explanation:
Python requires explicit handling of circular dependencies using techniques like late imports or rearranging code.

23.
What is the purpose of the __slots__ attribute in a Python class?
To define class attributes
To create a new instance of the class
To restrict the attributes that can be dynamically added to instances
To access superclass attributes directly
Answer: Option
Explanation:
The __slots__ attribute restricts the attributes that can be dynamically added to instances, improving memory efficiency.

24.
What is the purpose of the @property decorator?
To define a class property
To create a new instance of a class
To access class attributes directly
To override a method in the superclass
Answer: Option
Explanation:
The @property decorator is used to define a property in a class, allowing the use of the property like an attribute.

25.
What is the purpose of the __del__() method in Python classes?
To delete a class instance
To define class attributes
To create a new instance of the class
To access superclass attributes directly
Answer: Option
Explanation:
The __del__() method is called when an instance of a class is about to be destroyed, providing an opportunity for cleanup operations.