How will Triangle objects know which init method to use?
In this exercise we’ve defined a new
Triangle that inherits from the base class
Shape. Both classes define an
__init__() method! Luckily, Python is smart enough to see that we intended to use the initialize method in our
Triangle class when creating a new
Python checks the object that called the method and sees that it has a method of the same name that then takes priority over the one in the base class.
In the case of
__init__() being defined twice, it sees that we’re initializing a Triangle, so we use that method.