LimioLearn in Flow
🏆 Đấu trường
Đăng nhậpĐăng ký
← Programming for Data Science

Bạn đang xem thử công khai

Đăng nhập để lưu tiến độ, làm bài tập, thảo luận và nhận phản hồi.

Đăng nhập
Module 1: Fundamentals of Python Programming

1.11 Inheritance, Encapsulation, and Polymorphism

In / Lưu PDF

1.11 Inheritance, Encapsulation, and Polymorphism

After this unit you will: be able to tell apart the three most commonly confused concepts of OOP.

Key points

ConceptMeaningExample in this lesson
InheritanceA child class reuses everything from its parent class and can add to it or override it (an "is-a" relationship)class Dog(Animal)
EncapsulationProtecting internal data from being modified arbitrarilyself.__balance + deposit()
PolymorphismThe same method name, different behavior depending on the objectspeak() of Dog, Cat, Cow

Use super() to extend a parent class's method rather than replace it entirely.