0

I am new to python and migrating from C++ to python.

class B:
   def __init__(self): 
     print "Constructor B was called"
class C(B): 
    def __init__(self): 
     print "Constructor C was called"
c = C()

output of the above program is

Constructor C was called

expected output

Constructor B was called Constructor C was called

why parent constructor is not called like it would have been called in C++ .

masoud
  • 55,379
  • 16
  • 141
  • 208
  • 1
    In python you must explicitly call super class constructor. Explicit better than implicit. – masoud Jan 16 '16 at 12:21
  • If I don't call parent constructor Explicitly. Wouldn't it create problem in object creation? – user2809974 Jan 16 '16 at 13:18
  • From OOP point of view, yes it could have problems, but if you know what you're doing then objects can be created without calling parent's constructor properly. My recommendation is to call parent's constructor always. – masoud Jan 16 '16 at 13:31

0 Answers0