Monday 10 April 2023

Write a python program to demonstrate inheritance

 class Animal:

    name = ''

    type = 'carnivorous'


    def base_details(self):

        print(F'{self.name} & {self.type}')



class Dog(Animal):

    def features(self):

        self.name = "Puppy, Gradion, Tommy & jacob etc"

        features = "The dog is a mammal with sharp teeth, an excellent sense of smell, and a fine sense of hearing."

        print(f'Best friend of Human. Lovely names are {self.name}\nIt is {self.type}.\n{features}')



class Cat(Animal):

    def print_type(self):

        self.name = "Cat or Pussy"

        self.type = "herbivorous"

        print(f'{self.name} is a {self.type}.')



dog = Dog()

dog.features()


cat = Cat()

cat.print_type()


Output