You are missing some brackets at Bonny = Dog.
class Animal:
def talk(self, something):
print(something)
class Dog(Animal):
def talk(self):
super().talk("woof woof")
Bonny = Dog()
Bonny.talk()
EDIT
Since this is my top voted answer at the moment, and still has some activity, and it clearly lacks some explanation, I would like to add some.
Bonny = Dog
Means, Bonny is a reference to the Dog class. It is callable, and would the the instance of Dog. Bonny won't be a type.
Bonny = Dog()
If you would like to call the object like above, you should add the brackets. That means you call the object, and referring to it. Bonny will be a reference.
Also references to object should be lowercase.
bonny = Dog()
Second thing. Since your objects indicates they may contain data corresponding to each object of the same type (2 or more Dog objects), so there is a need for a constructor.
class Dog(Animal):
def __init__(self, name):
super(Dog, self).__init__(self)
self.name = name
def talk(self):
super().talk("woof woof my name is {}".format(self.name))
def __str__(self):
return self.name
This way you can name your dog, make him say his name, and on print(bonny), also print his name using the __str__ method. But also you need to call the super's (in this case the Animal objects) init function, using the super function, used by the OP.
Class inheritence isn't the easiest thing in Python, since it is not a strongly OO language. But classes are awesome!
print(type(Dog), type(Dog())). This example is a bit strange overall.Bonny = Dog()to Instantiate the object.