โ† All POC Flashcard Decks

Object-Oriented Programming in Python Flashcards

7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Object-Oriented Programming in Python flashcards as text
  1. What is the purpose of the `__str__` method in a Python class?

    Answer: To return a human-readable string representation of an object

    `__str__` returns a user-friendly string representation used by `print()` and `str()` functions.

  2. Which keyword is used to inherit from a parent class in Python?

    Answer: Parentheses with the parent class name in the class definition

    Python uses parentheses in the class definition (e.g., `class Child(Parent):`) to indicate inheritance.

  3. What does `super().__init__()` do in a child class?

    Answer: Calls the parent class's `__init__` method to initialize inherited attributes

    `super().__init__()` invokes the parent class constructor so inherited attributes are properly set up.

  4. Which of the following best describes method overriding?

    Answer: Defining a method with the same name in a child class to replace the parent's implementation

    Method overriding allows a subclass to provide a specific implementation for a method already defined in its parent class.

  5. What will `isinstance(obj, MyClass)` return if `obj` is an instance of a subclass of `MyClass`?

    Answer: True

    `isinstance()` returns `True` for instances of the class and all its subclasses.

  6. Which access modifier convention in Python indicates a method is intended for internal use only?

    Answer: A single underscore prefix

    A single leading underscore (e.g., `_method`) is a convention signaling the method is intended for internal/protected use.

  7. What is name mangling in Python?

    Answer: Transforming `__attr` to `_ClassName__attr` to avoid name conflicts in subclasses

    Name mangling transforms double-underscore prefixed names (e.g., `__x`) to `_ClassName__x` to prevent accidental override in subclasses.