Python Object-Oriented Programming Concepts Challenge Quiz

  1. Understanding Class Definition

    In Python, which statement correctly defines a class named Vehicle with no methods or attributes?

    1. def class Vehicle(): pass
    2. Vehicle class: pass
    3. class Vehicle: pass
    4. define Vehicle: pass
    5. Vehicle(): class pass
  2. Object Instantiation

    Given the class definition 'class Gadget:', which of the following methods correctly creates an object of this class?

    1. device = Gadget
    2. device = Gadget.new()
    3. device = new Gadget()
    4. device = Gadget(object)
    5. device = Gadget()
  3. Encapsulation with Private Attributes

    How can you declare an attribute as private so that it cannot be directly accessed from outside a class called Account?

    1. self.balance = 0
    2. self._balance = 0
    3. self.__balance = 0
    4. self::balance = 0
    5. self.private balance = 0
  4. Multiple Inheritance Resolution Order

    Given classes X, Y, Z and class W(X, Y, Z), what determines the method resolution order (MRO) when invoking W's methods?

    1. C3 linearization
    2. Post-order traversal
    3. Depth-first traversal
    4. Zigzag pattern
    5. BFS Algorithm
  5. Polymorphism and Method Overriding

    If a subclass implements a method with the same name as its superclass, what feature is demonstrated when the subclass's method is called instead?

    1. Method overriding
    2. Method shadowing
    3. Data wrapping
    4. Function hiding
    5. Method overbidding
  6. Abstract Base Classes

    What is required for a class in Python to be considered an abstract class?

    1. It must use the 'abstract' keyword in its declaration.
    2. It must define methods prefixed with 'abs_'.
    3. It must have only static methods.
    4. It must inherit from object and contain virtual methods.
    5. It must inherit from abc.ABC and have at least one @abstractmethod.
  7. Operator Overloading with Special Methods

    Which special method in a class allows overloading the addition operator ('+') for custom objects?

    1. __add__
    2. __concat__
    3. __append__
    4. __sum__
    5. __plus__
  8. Using the @property Decorator

    How does the @property decorator enhance attribute access in Python classes?

    1. It allows methods to be accessed like attributes.
    2. It turns class methods into instance methods.
    3. It automatically creates class-level variables.
    4. It hides all attributes from subclasses.
    5. It makes attributes static and read-only.
  9. Name Mangling for Double Underscore Attributes

    When an attribute is named with double leading underscores (e.g., __value), how does Python handle it internally?

    1. It completely restricts access from outside the class.
    2. It converts underscores to hyphens in the name.
    3. It encrypts the attribute automatically.
    4. It throws an AttributeError during runtime.
    5. It performs name mangling by prefixing with _ClassName.
  10. Static Methods versus Class Methods

    Which of the following statements best differentiates a static method from a class method in Python?

    1. A static method can access instance variables directly, but a class method cannot.
    2. A class method can only be called from outside the class.
    3. Both types of methods are identical in behavior.
    4. A static method receives the class as the first argument, while a class method does not.
    5. A class method receives the class as its first argument, while a static method does not receive any implicit first argument.
  11. Diamond Problem in Multiple Inheritance

    In multiple inheritance, what is the diamond problem, and how does Python resolve it?

    1. It occurs when two base classes share a common ancestor; Python resolves it using the MRO.
    2. It refers to circular imports; Python resolves it with sys.path manipulation.
    3. It is caused by conflicting variable names; Python throws a RuntimeError.
    4. It arises from private inheritance; Python ignores duplicated methods.
    5. It happens if a class inherits from itself; Python stops compilation.
  12. Duck Typing in Polymorphism

    Given two classes, both defining a method named 'quack', which concept allows using them interchangeably in a function expecting 'quackable' objects?

    1. Protocol subclassing
    2. Type checking
    3. Single dispatch
    4. Duck typing
    5. Explicit interface
  13. Calling Superclass Methods

    Which syntax correctly invokes a method called 'move' from a superclass in a subclass's method?

    1. this.move()
    2. self.super(move)
    3. super().move()
    4. base.move(self)
    5. superclass:move()
  14. Abstract Method Enforcement

    What happens if a subclass does not implement all abstract methods of its abstract base class when instantiated?

    1. The missing methods default to pass.
    2. The class instance is silently created.
    3. A TypeError is raised during instantiation.
    4. An ImportError is thrown.
    5. A warning is issued at runtime.
  15. Operator Overloading for Equality

    Which special method should be defined to overload the equality operator '==' for a custom class?

    1. __equal__
    2. __equals__
    3. __isequal__
    4. __eq__
    5. __equiv__