How Child Class Can Use Parent's Stuff (Constructor Edition)

I have one question: if I want to access a parent class property, do I need to define super, or can I access it directly using self?

If the parent constructor is already being called, then:

  • βœ… you don’t need super() just to access parent property

  • βœ… you can simply use self.property_name anywhere in child class


🧠 Suppose this:

class BankAccount:
    def __init__(self):
        self.bank_name = "SBI"

    def show_bank(self):
        print(f"This is {self.bank_name}")
class SavingsAccount(BankAccount):
    def show_details(self):
        print(self.bank_name)  # βœ… parent property
        self.show_bank()       # βœ… parent method

βœ… This will work perfectly because SavingsAccount didn't override the parent constructor because in a child we didn’t create any child class constructor
β†’ So Python automatically called the parent one

acc = SavingsAccount()
acc.show_details()

⚠️ but if you override constructor:

class SavingsAccount(BankAccount):
    def __init__(self):
        self.type = "Savings"

Now when you do:

acc = SavingsAccount()
print(acc.bank_name)

❌ It will give error β†’ AttributeError: 'SavingsAccount' object has no attribute 'bank_name'

Why?

β†’ Because you wrote your own constructor, so Python skipped the parent one
β†’ And you didn’t call super().__init__()


βœ… Fix it like this:

class SavingsAccount(BankAccount):
    def __init__(self):
        super().__init__()  # brings bank_name
        self.type = "Savings"

Now:

print(self.bank_name)  # βœ… works

So summary:

  • If no child constructor β†’ parent constructor auto-called β†’ you can use self

  • If child has its own constructor β†’ use super().__init__() to bring parent things

Updated on