课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Working with inheritance and polymorphism - Python教程
课程: 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…