11. What is a decorator used for in advanced OOP? A. Adding new attributes to classes B. Defining new classes C. Modifying methods or functions behavior D. Creating abstract classes Answer & Solution Discuss in Board Save for Later 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? A. To define a class as a singleton B. To restrict the attributes that can be added to instances C. To define class methods D. To define class attributes Answer & Solution Discuss in Board Save for Later 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? A. Binding of methods during runtime B. Binding of methods during compilation C. Binding of attributes during runtime D. Binding of attributes during compilation Answer & Solution Discuss in Board Save for Later 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? A. To define methods that operate on instances B. To define methods that operate on classes C. To define methods that can be overridden D. To define methods that require arguments Answer & Solution Discuss in Board Save for Later 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? A. Shallow copies copy nested objects B. Deep copies copy only the outer object C. Shallow copies copy references to nested objects D. Deep copies copy nested objects Answer & Solution Discuss in Board Save for Later 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? A. To define a setter method for a class attribute B. To define a getter method for a class attribute C. To add properties to classes D. To define methods for instance attributes Answer & Solution Discuss in Board Save for Later 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? A. By creating new operators B. By using built-in operators on class objects C. By adding new methods to built-in operators D. By modifying built-in operators Answer & Solution Discuss in Board Save for Later 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? A. To convert an object to a string B. To define the string representation of an object C. To create a copy of an object D. To initialize object attributes Answer & Solution Discuss in Board Save for Later 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? A. By using only class inheritance B. By using only class composition C. By using both class inheritance and composition D. By using multiple inheritance only Answer & Solution Discuss in Board Save for Later 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? A. Composition allows creating new classes B. Inheritance allows creating new classes C. Composition involves using existing classes D. Inheritance involves using existing classes Answer & Solution Discuss in Board Save for Later 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.