Kode Python untuk menunjukkan warisan dengan kelas hewan

class Animal():
    def __init__(self, name, age):
        self.name = name
        self.age = age 

    def speak(self):
        print("I am", self.name, "and I am", self.age, "years old")


class Dog(Animal):
    def __init__(self, name, age)
        self.name = name
        self.age = age
        self.type = "dog"

    # Since we inherit from the animal class we can use the method speak on Dog objects


tim = Dog("Tim", 5)
tim.speak() # This will print "I am Tim and I am 5 years old"
mathiasgodwin