Bird
0
0

Which of the following is the correct way to define an Expense class constructor in Python?

easy📝 Conceptual Q3 of 15
LLD - Design — Splitwise (Expense Sharing)
Which of the following is the correct way to define an Expense class constructor in Python?
Adef __start__(self, amount, paid_by):
Bdef Expense(self, amount, paid_by):
Cdef init(self, amount, paid_by):
Ddef __init__(self, amount, paid_by):
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python constructor syntax

    Python constructors use __init__ method with self parameter.
  2. Step 2: Check options for correct syntax

    Only def __init__(self, amount, paid_by): uses __init__ correctly with self and parameters.
  3. Final Answer:

    def __init__(self, amount, paid_by): -> Option D
  4. Quick Check:

    Constructor syntax = __init__ [OK]
Quick Trick: Python constructors use __init__ method [OK]
Common Mistakes:
  • Using method name same as class
  • Missing underscores in __init__
  • Using wrong method names like init or __start__

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes