1. What is encapsulation in object-oriented programming (OOP)? A. Exposing internal details of an object B. Grouping data and methods into a single unit C. Hiding data and methods within an object D. Inheriting from multiple classes Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: Encapsulation involves hiding the internal implementation details of an object and exposing a controlled interface.
2. What is the main benefit of encapsulation? A. Improved code readability B. Faster execution C. Enhanced security D. Better memory management Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: Encapsulation enhances security by controlling access to data and methods of an object.
3. What is inheritance in OOP? A. Creating new objects from existing ones B. Allowing objects to share attributes and methods C. Restricting access to object attributes D. Converting classes into objects Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option B Solution: Inheritance allows objects to inherit attributes and methods from a parent class.
4. What is an abstract class in OOP? A. A class that cannot be instantiated B. A class with no attributes C. A class with only attributes D. A class that cannot have methods Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option A Solution: An abstract class cannot be instantiated and often serves as a blueprint for other classes.
5. What is a method resolution order (MRO) in Python? A. The order of methods in a class B. The order in which classes are defined C. The order in which methods are executed D. The order in which base classes are searched Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D Solution: The method resolution order (MRO) determines the order in which base classes are searched for a method or attribute.
6. What is multiple inheritance in OOP? A. Inheriting attributes from multiple classes B. Creating multiple instances of a class C. Inheriting from multiple subclasses D. Inheriting from multiple base classes Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option D Solution: Multiple inheritance involves inheriting attributes and methods from multiple base classes.
7. How is the super() function used in Python inheritance? A. To create new instances of a class B. To call the base class constructor C. To create subclass methods D. To override base class methods Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option B Solution: The super() function is used to call the constructor of the base class in a subclass.
8. What is method overloading in Python? A. Using multiple methods with the same name but different parameters B. Using methods with different names but the same parameters C. Using methods with the same name and parameters D. Using methods with different names and different parameters Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option A Solution: Method overloading involves defining multiple methods with the same name but different parameters.
9. What is method overriding in Python? A. Replacing a method with a new method B. Defining a method in a subclass with the same name as in the base class C. Calling a method from a different class D. Creating a new method in a subclass Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option B Solution: Method overriding involves defining a method in a subclass with the same name as in the base class to modify its behavior.
10. What is a metaclass in Python? A. A class with multiple methods B. A class that inherits from all other classes C. A class that defines the structure of other classes D. A class that cannot be instantiated Answer & Solution Discuss in Board Save for Later Answer & Solution Answer: Option C Solution: A metaclass is a class that defines the structure of other classes, serving as a class template.