Trying to understand multiple inheritance.
I have created a parent class called 'Human' and from it created a child class called 'Man'. This child class inherits all attributes and methods except that the human_gender attribute is overwritten and set to 'male'. - this all works fine and as expected.
What I then tried to do it created a new child class called 'BoyChild' (from 'Man') which I hoped would inherit all of man's attributes and methods except that I wished to overwrite the age attribute to set the age to 8. This is throwing up an error.
Why is this error occurring? If I remove 'age=8' from the super().init parentheses, it inherits as normal, but I can't seem to overwrite the inherited class' attribute 'age'.
class human():
'''This is a human class'''
def __init__(self, human_gender = "unknown", age = 0,
hunger_level=0):
self.human_gender = human_gender
self.age = age
self.hunger_level = hunger_level
def setGender(self):
self.human_gender = input("Please enter human's gender:")
def setAge(self):
self.age = int(input("Please enter human's age"))
def setHunger_level(self):
self.hunger_level = int(input("Please enter human's hunger level (0-10)"))
class man(human):
'''This is a Man class'''
def __init__(self):
super().__init__(human_gender="male")
class boychild(man):
'''This is a Boychild class'''
def __init__(self):
super().__init__(age=8)
guy = boychild()
#guy.setGender()
#guy.setAge()
guy.setHunger_level()
print("The human is a: ", guy.human_gender)
print("The human is: ", guy.age)
print("The human's hunger level is: ", guy.hunger_level)
input()