<
RHD
/>
Home
Blog
Quiz
Resources
About
Contact
Enlist
// guest
▾
Login
Request Account
[ light ]
// Object-oriented programming
Object-oriented programming Quiz
// question 1 of 10
What is operator overloading?
Using the same operator in multiple expressions
Defining special methods to give operators custom behavior for a class
Calling an operator method directly
// question 2 of 10
What is the single responsibility principle?
Each file should contain only one class
Each class should have one clear purpose
Each method should take only one argument
// question 3 of 10
What is a data class in Python?
A class that inherits from dict
A class decorated with @dataclass that auto-generates __init__ and __repr__
A class that only stores data with no methods
// question 4 of 10
What is the correct way to check if an object is an instance of multiple classes?
obj.type in [ClassA, ClassB]
isinstance(obj, (ClassA, ClassB))
type(obj) == ClassA or ClassB
// question 5 of 10
What does setattr(obj, 'name', value) do?
Raises an error if the attribute already exists
Creates a new method on obj
Sets the attribute name to value on obj
// question 6 of 10
What happens when you assign a value to a class attribute through an instance?
A TypeError is raised
The class attribute is modified for all instances
A new instance attribute is created that shadows the class attribute
// question 7 of 10
What is the output of Animal.count when count is a class attribute set to zero?
None
0 for all instances that have not overridden it
An AttributeError because count is not on an instance
// question 8 of 10
What happens if you forget to write self.name equals name in __init__?
The attribute is stored on the class instead
The program raises a NameError immediately
The value is stored as a local variable and lost after __init__ finishes
// question 9 of 10
What is an instance attribute?
An attribute shared by all objects of the class
An attribute unique to each individual object
An attribute defined outside __init__
// question 10 of 10
What is method overriding?
Defining two methods with the same name in one class
A child class redefining a method from the parent class
Calling a method with different arguments
Submit Answers →