Bird
Raised Fist0

Given this code, what will print(obj.info()) output?

hard🚀 Application Q9 of Q15
Python - Inheritance and Code Reuse
Given this code, what will print(obj.info()) output?
class Vehicle:
    def info(self):
        return "Vehicle info"

class Car(Vehicle):
    def info(self):
        parent_info = super().info()
        return parent_info + ", Car details"

obj = Car()
print(obj.info())
AVehicle info, Car details
BCar details
CVehicle info
DError: super() not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand super() usage

    super().info() calls the parent class's info method, returning "Vehicle info".
  2. Step 2: Combine strings in child method

    Child's info adds ", Car details" to parent's string.
  3. Final Answer:

    Vehicle info, Car details -> Option A
  4. Quick Check:

    super() calls parent method correctly [OK]
Quick Trick: Use super() to extend parent methods [OK]
Common Mistakes:
MISTAKES
  • Expecting only child string
  • Thinking super() causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes