ExamVeda
Login
Home
11
What is a decorator used for in advanced OOP?
Discuss
Answer & Solution
Answer: Option C
Solution:
Decorators are often used to modify the behavior of methods or functions in advanced OOP.
12
What is the purpose of the __slots__ attribute in Python classes?
Discuss
Answer & Solution
Answer: Option B
Solution:
The __slots__ attribute restricts the attributes that can be added to instances, optimizing memory usage.
13
What is dynamic binding in OOP?
Discuss
Answer & Solution
Answer: Option A
Solution:
Dynamic binding involves determining the method to call during runtime based on the object's type.
14
What is the purpose of the @staticmethod decorator in advanced OOP?
Discuss
Answer & Solution
Answer: Option B
Solution:
The @staticmethod decorator is used to define methods that operate on classes, not instances.
15
What is the difference between a shallow copy and a deep copy in Python?
Discuss
Answer & Solution
Answer: Option C
Solution:
Shallow copies copy references to nested objects, while deep copies create entirely new objects.
16
What is the purpose of the @property decorator in advanced OOP?
Discuss
Answer & Solution
Answer: Option B
Solution:
The @property decorator is used to define a getter method for a class attribute, allowing access as a property.
17
How does operator overloading work in Python classes?
Discuss
Answer & Solution
Answer: Option C
Solution:
Operator overloading involves defining methods that specify behavior for built-in operators on class objects.
18
What is the purpose of the __str__() method in Python classes?
Discuss
Answer & Solution
Answer: Option B
Solution:
The __str__() method defines the string representation of an object, often used with the str() function.
19
How is polymorphism achieved in Python?
Discuss
Answer & Solution
Answer: Option C
Solution:
Polymorphism is achieved in Python through both class inheritance and composition.
20
What is the difference between class composition and class inheritance?
Discuss
Answer & Solution
Answer: Option C
Solution:
Class composition involves using existing classes to build more complex ones, while inheritance involves creating new classes based on existing ones.