What is the relation between the dog and animal classes in this Python code? -
class animal(object): pass class dog(animal): def __init__(self): print "i got called"
i found code in book "learn python hard way". have questions relationship between dog
, animal
?
are dog
, animal
both classes , dog
inherit animal
?
the class dog
inherited class animal
. means object of class dog
gets attributes , methods animal
class defines. class dog
called subclass
or inherited
class while class animal
called superclass
or parent
class.
usually subclass used extend functionality of class. class dog
can modify attributes and/or functionalities of animal
and/or add own.