Reputation: 4764
As shown in the code, Dog
is a subclass of Pet
. When I create an instance of Dog
, I can't get the species
of it. By the way, I am following this article?
class Pet(object):
def __init__(self, name, species):
self.name = name
self.species = species
def getName(self):
return self.name
def getSpecies(self):
return self.species
def __str__(self):
return "{0} is a {1}".format(self.name, self.species)
class Dog(Pet):
def __int__(self, name, chaseCats):
Pet.__init__(self, name, "dog")
self.chaseCats = chaseCats
def getChaseCats(self):
return self.chaseCats
When create an instance:
mister_dog = Dog("Huang ~", True)
print mister_dog.getSpecies()
It returns: True
rather than dog
.
Upvotes: 0
Views: 512
Reputation: 43024
It's a typo. The subclass Dog
first method is named __int__
, rather than __init__
. Therefore the initializer is not being defined in the subclass and you are only calling the base class's __init__
directly.
By the way, you could start using the super()
method as well, rather than the unbound method.
Upvotes: 4