method overriding
Defining a method in a subclass with the same name as one in its parent, so the subclass's version is used instead.
In more detail
The overriding method can still call the parent's version through super(), for example to add a step before or after it. Python finds the overriding method first because it searches the subclass before its parents.
Related terms
- inheritance — Declaring one class or type as a specialised version of another, so it receives the parent's members and can be used wherever the parent is expected.
- super() — A built-in that lets a method call the version of itself in the parent class, most often super().__init__(...) in an initialiser.
Taught in
- Installing Python On Linux — Hands-on Python: Complete Video Course & Book
- Integer Arithmetic And Precedence — Hands-on Python: Complete Video Course & Book
- The Print Function And String Literals — Hands-on Python: Complete Video Course & Book
- Inheritance And Composition — Hands-on Python: Complete Video Course & Book
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Introspection: hasattr, __name__, __module__ And __bases__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Inheritance, super() And Polymorphism — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Multiple Inheritance, The MRO And Diamonds — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Special Methods: __str__, __eq__ And Friends — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Object-Oriented Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep