Write a Python program to demonstrate inheritance. The program should have a base class called Animal and a child class called Dog. The Animal class should have a method called eat(). The Dog class should inherit the eat() method from the Animal class and also have a method called bark().
Codes:
class Animal:
def eat(self):
print("The animal is eating.")
class Dog(Animal):
def bark(self):
print("The dog is barking.")
# Create an instance of Dog
dog = Dog()
# Demonstrate inheritance
dog.eat() # Inherited from Animal class
dog.bark() # Defined in Dog class
0 Comments