Python Programming - Inheritance

Exercise : Inheritance - General Questions
  • Inheritance - General Questions
26.
What is the purpose of the __getattr__() method?
To define class attributes
To create a new instance of the class
To customize attribute access for undefined attributes
To access superclass attributes directly
Answer: Option
Explanation:
The __getattr__() method is called when attempting to access an undefined attribute, allowing customization of attribute access.

27.
In Python, what is the purpose of the __getattribute__() method?
To define class attributes
To create a new instance of the class
To customize attribute access for all attributes
To access superclass attributes directly
Answer: Option
Explanation:
The __getattribute__() method is called for all attribute access, providing a way to customize attribute access behavior.

28.
What is a metaclass?
A class that inherits from multiple classes
A class that defines class attributes
A class used to create and customize class instances
A class that overrides methods in its superclass
Answer: Option
Explanation:
A metaclass in Python is a class used to create and customize the behavior of class instances, allowing modification of class creation and initialization.

29.
How does Python handle name mangling for attributes in a class?
All attributes are automatically private
Attributes with a single leading underscore are considered private
Attributes with a double leading underscore undergo name mangling
Name mangling is not supported in Python
Answer: Option
Explanation:
Attributes with a double leading underscore in Python undergo name mangling, which involves adding a prefix based on the class name to avoid naming conflicts.

30.
How can you achieve method overriding in Python without using the super() function?
By using the @override decorator
By explicitly calling the superclass method
Method overriding is not possible without super()
By redefining the method in the subclass with the same name
Answer: Option
Explanation:
Method overriding in Python can be achieved by redefining a method in the subclass with the same name as in the superclass.