- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How we can extend multiple Python classes in inheritance?
As per Python documentation ‘super’ can help in extending multiple python classes in inheritance. It returns a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped.
In other words, a call to super returns a fake object which delegates attribute lookups to classes above you in the inheritance chain. Points to note:
This does not work with old-style classes.You need to pass your own class and instance to super in Python 2.x. This requirement was waived in 3.x.
This will handle all multiple inheritance correctly. A method resolution order is generated and the lookups go through parent classes in this order.
- Related Articles
- Does Java support multiple inheritance? Why? How can we resolve this?
- Introduction to Classes and Inheritance in Python
- How we can instantiate different python classes dynamically?
- How does class variables function in multi-inheritance Python classes?
- Can an interface extend multiple interfaces in Java?
- Can an interface in Java extend multiple interfaces?
- Explain Inheritance vs Instantiation for Python classes.
- Can we extend an enum in Java?
- Can we extend interfaces in Java? Explain?
- How we can bundle multiple python modules?
- Does Python support multiple inheritance?
- How can we print multiple blank lines in python?
- How we can split Python class into multiple files?
- Multiple Inheritance in C++
- Multiple inheritance in JavaScript
