From the course: Python: Design Patterns (2021)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Working with inheritance and polymorphism - Python Tutorial
From the course: Python: Design Patterns (2021)
Working with inheritance and polymorphism
- There are some additional key concepts to master in object oriented programming. We'll get started with inheritance. Inheritance establishes relationships between classes as parent and child. The child class keeps all the attributes and methods of its parent. It can also add new attributes or methods of its own to the parent class definition. The child class can also override the existing methods of its parent. Let's say that we have a pet class with two child classes, dog and cat. These child classes share a common attribute: the name. They're inheriting from their parent class path. However, the child classes override the speak method in their definition. The dog class overrides its speak method to produce the barking sound while the cat class overrides the same method to create the meow sound. Another object oriented class concept important to understand is polymorphism. Polymorphism relies on inheritance and…