How to write a Python program that has a base class with methods and attributes , subclasses with methods and attributes. Please use any example you'd like.
class Animal: def __init__(self, type, name): self.type = type self.name = name def getType(self): return self.type def getName(self): return self.name def setType(self, type): self.type = type def setName(self, name): self.name = name class Cat(Animal): def __init__(self, type, name, age): super().__init__(type, name) self.age = age def getAge(self): return self.age def setAge(self, age): self.age = age # Testing c = Cat("type1","billy",4) print(c.getName())
billy
Get Answers For Free
Most questions answered within 1 hours.