In this we are going to see a basic program on class inheritance with animal class example in Python Programming Language.
class Dog:
animal = 'dog'
def __init__(self, breed, color):
self.breed = breed
self.color = color
class Cat:
animal = 'cat'
def __init__(self, breed, color):
self.breed = breed
self.color = color
Rocky = Dog("Pug", "brown")
Pom = Cat("Persian", "white")
print('Rocky details:')
print('Rocky is a', Rocky.animal)
print('Breed:', Rocky.breed)
print('Color:', Rocky.color)
print('\nPom details:')
print('Pom is a', Pom.animal)
print('Breed:', Pom.breed)
print('Color:', Pom.color)
#Coded by SAAHIL
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP