Inheritance in Python for Code Reuse


Use inheritance to create a new class that inherits attributes and methods from an existing class.

Source Code

class Animal:
    def greet(self):
        print("Hello, I am an animal.")
class Dog(Animal):
    def greet(self):
        super().greet()
        print("And I am also a dog.")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments