I am experimenting with basic python inheritance with a Dog class that inherits from an Animal class. For some reason, my Dog object is not inheriting name correctly and I keep getting AttributeError: 'Dog' object has no attribute '_Dog__name'. Does anyone know what might be going on? My code is below:
class Animal(object):
__name = None #signifies lack of a value
__height = 0
__weight = 0
__sound = 0
def __init__(self, name, height, weight, sound):
self.__name = name
self.__height = height
self.__weight = weight
self.__sound = sound
class Dog(Animal):
def __init__(self, name, height, weight, sound, owner):
super(Dog, self).__init__(name, height, weight, sound)
self.__owner = owner
#self.__name = name this works if I uncomment this line.
__owner = ""
def toString(self):
return "{} belongs to {}".format(self.__name, self.__owner)
#return 'Sup dawg'
fido = Dog("Spot", 3, 4, "Woof", "John")
print(fido.toString())
toString?