课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Inheritance and polymorphism - Python教程
课程: Advanced Python: Build Hands-On Projects with Design Patterns (2023)
Inheritance and polymorphism
- [Instructor] Inheritance and polymorphism are key concepts that help you understand how design patterns work. Let's get started with inheritance. Inheritance establishes relationships between two classes as a parent and a 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 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, pet. 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.…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。