I am a newbie in Python so please bear with me if the question is very simple for you.
Can someone explain why the class variable, name, in Dog class causes an error in the following example? It doesn't make sense to me that d.name
is ok to be called, but d.eat() is not ok for method overloading. Thank you very much in advance for your help!
class Animal: # parent class
name = 'Animal'
def eat(self):
print "Animal eating"
class Dog(Animal): # child class
name = 'Dog'
def eat(self):
print name
d = Dog()
print d.name # OK
d.eat() # Error !