Bird
0
0

Which of the following is a syntax error when defining a class with multiple inheritance?

easy📝 Syntax Q12 of 15
Python - Multiple Inheritance and Method Resolution
Which of the following is a syntax error when defining a class with multiple inheritance?
Aclass MyClass(): pass
Bclass MyClass(Parent1, Parent2): pass
Cclass MyClass(Parent1): pass
Dclass MyClass(Parent1 Parent2): pass
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for multiple inheritance

    Parent classes must be separated by commas inside parentheses.
  2. Step 2: Identify the incorrect option

    class MyClass(Parent1 Parent2): pass misses the comma between Parent1 and Parent2, causing a syntax error.
  3. Final Answer:

    class MyClass(Parent1 Parent2): pass -> Option D
  4. Quick Check:

    Missing comma between parents = SyntaxError [OK]
Quick Trick: Always separate parent classes with commas [OK]
Common Mistakes:
  • Omitting commas between parent classes
  • Leaving out parentheses entirely
  • Using colons instead of commas

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes