21. What is the purpose of the __eq__() method in Python classes? A. To create an instance of a class B. To compare two instances for equality C. To modify object attributes D. To convert an object to a string Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option B Solution: The __eq__() method defines how instances of a class are compared for equality using the == operator.
22. What is the diamond problem in multiple inheritance? A. A problem with defining diamond shapes B. A problem with multiple inheritance in shapes C. A problem with ambiguous method resolution D. A problem with creating classes in diamond shapes Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: The diamond problem refers to the ambiguity that arises when a class inherits from two classes that have a common ancestor.
23. What is the role of the @abstractmethod decorator in advanced OOP? A. To create abstract classes B. To prevent method overriding C. To indicate that a method must be overridden in subclasses D. To define a method as static Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: The @abstractmethod decorator indicates that a method must be overridden in subclasses.
24. How can you implement method overloading in Python? A. By defining multiple methods with the same name but different parameters B. By using the @overload decorator C. By using the @methodoverload decorator D. By defining methods with different names Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option A Solution: Method overloading is achieved by defining multiple methods with the same name but different parameters.
25. What is the purpose of the super() function in advanced OOP? A. To call the base class constructor B. To create a new instance of a class C. To override base class methods D. To define class attributes Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option A Solution: The super() function is used to call the constructor of the base class in a subclass.