WorksheetsPython Inheritance and Methods Quiz
Total questions: 10
Worksheet time: 5mins
Which of the following statements correctly describes inheritance in Python?
It allows a class to create multiple instances.
It allows a class to hide its attributes and methods.
It allows a class (subclass) to inherit attributes and methods from another class (superclass), promoting code reuse.
It allows a class to override its parent class methods without inheriting them.
Which of the following is not a type of inheritance?
Double-level
Multi-level
Single-level
Multiple
What type of inheritance is illustrated in the following Python code? class A(): pass class B(A): pass class C(B): pass
Multi-level inheritance
Multiple inheritance
Hierarchical inheritance
Single-level inheritance
What is the purpose of the __init__ method in a Python class?
To initialize the class object with default attributes.
To create a new instance of the class.
To define the constructor of the class.
To destroy the class object.
What is the purpose of the "pass" statement in Python?
The "pass" statement is used to indicate methods undefined and will do nothing.
The "pass" statement is used to exit a loop.
The "pass" statement is used to define a class.
The "pass" statement is used to call another method.
Which dunder method is used to implement the behavior of the ' / ' operator in Python?
__div__
__truediv__
__floordiv__
None of these
What is the purpose of the __setattr__ method in Python?
It is used to set the value of an attribute.
It is used to define the behavior of attribute assignment.
It is used to check if an attribute exists.
It is used to delete an attribute.
Which dunder method is used to implement the behavior of the != operator in Python?
__ge__
__eq__
__le__
__ne__
What does the __add__ method do in Python?
It adds two objects together.
It concatenates two objects.
It performs element-wise addition for two objects.
It performs matrix multiplication for two objects.
Which of the following statements about function arguments in Python is true?
All arguments must have default values
Functions cannot have more than one argument
Arguments are passed by value
Arguments can have default values
