When inheriting in python, i got following error with private variables:
AttributeError: 'dog' object has no attribute '_dog__name'
I searched a lot but didn't understand where my problem is;
class animal(object):
__name = ""
__height = ""
__weight = ""
__sound = ""
def __init__(self, name, height, weight, sound):
self.__name = name
self.__height = height
self.__weight = weight
self.__sound = sound
def toString(self):
return "{} is {} cm and {} weight and say {}.".format(self.__name, self.__height, self.__weight, self.__sound)
class dog(animal):
__owner = ""
def __init__(self, name, height, weight, sound, owner):
self.__owner = owner
super(dog, self).__init__(name, height, weight, sound)
def toString(self):
return "{} is {} cm and {} weight and say {} and belongs to {}.".format(self.__name, self.__height,
self.__weight, self.__sound,
self.__owner)
puppy = dog('puppy', 45, 15, 'bark', 'alex')
puppy.toString()