Exercise: Inheritance
Questions for: Inheritance
How does Python handle name mangling for attributes in a class?
A:
All attributes are automatically private
B:
Attributes with a single leading underscore are considered private
C:
Attributes with a double leading underscore undergo name mangling
D:
Name mangling is not supported in Python
Answer: C
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.
What is a metaclass?
A:
A class that inherits from multiple classes
B:
A class that defines class attributes
C:
A class used to create and customize class instances
D:
A class that overrides methods in its superclass
Answer: C
A metaclass in Python is a class used to create and customize the behavior of class instances, allowing modification of class creation and initialization.
Discuss About this Question.
In Python, what is the purpose of the
__getattribute__() method?
A:
To define class attributes
B:
To create a new instance of the class
C:
To customize attribute access for all attributes
D:
To access superclass attributes directly
Answer: C
The
__getattribute__() method is called for all attribute access, providing a way to customize attribute access behavior.Discuss About this Question.
What is the purpose of the
__getattr__() method?
A:
To define class attributes
B:
To create a new instance of the class
C:
To customize attribute access for undefined attributes
D:
To access superclass attributes directly
Answer: C
The
__getattr__() method is called when attempting to access an undefined attribute, allowing customization of attribute access.Discuss About this Question.
What is the purpose of the
__del__() method in Python classes?
A:
To delete a class instance
B:
To define class attributes
C:
To create a new instance of the class
D:
To access superclass attributes directly
Answer: A
The
__del__() method is called when an instance of a class is about to be destroyed, providing an opportunity for cleanup operations.Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.