-1

I'm getting an error in python multilevel class inheritance.
This is my code:

class Animal():
    def __init__(self):
        print("Animal created")
    def whoAmI(self):
        print("Animal")
    def eat(self):
        print('eating')

class Dog(Animal):
    print("dog created")

class Cat(Dog):
    print("car created")

m = Cat()
Cat.eat()

This is the error I am getting:

enter image description here

Tobias Wilfert
  • 919
  • 3
  • 14
  • 26

1 Answers1

0

Your code should be like this:

m = Cat()
m.eat()

m is an instance of class Cat and as such, you can call eat() on it. You cannot call eat on the Cat itself unless you say Cat().eat().
This has little to do with inheritance as this code also gives you an error:

Animal.eat()

Also, cat should inherit directly from Animal and not dog.

Tobias Wilfert
  • 919
  • 3
  • 14
  • 26