29
loading...
This website collects cookies to deliver better user experience
class animal:
food=""
def makenoise(Self):
pass
class pet():
def bepetted(self):
print("Pet me")
class canine():
def shownails(self):
print("My nails are long")
class dog(pet):
def __init__(self):
print("I am a dog")
self.food="bone"
def makenoise(self):
print("Woof!")
class cat(pet,canine):
def __init__(self):
self.food="milk"
print("I am a cat")
def makenoise(self):
print("meow!")
Tommy=dog()
Tommy.makenoise()
Tommy.bepetted()
print(Tommy.food)
Dina=cat()
Dina.shownails()
Dina.bepetted()
print(Dina.food)
I am a dog
Woof!
Pet me
bone
I am a cat
My nails are long
Pet me
milk
class sample():
def fun(self):
print("yo!")
mysample=sample()
sample.fun()
Traceback (most recent call last):
File "main.py", line 6, in <module>
sample.fun()
TypeError: fun() missing 1 required positional argument: 'self'
class sample():
def fun():
print("yo!")
mysample=sample()
mysample.fun()
Traceback (most recent call last):
File "main.py", line 6, in <module>
mysample.fun()
TypeError: fun() takes 0 positional arguments but 1 was given
super()
method in case of overloading.