Overriding is an OOP’s (object-oriented programming) concept and generally we deal with this concept in Inheritance. Method overriding is an ability of any object-oriented programming language that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes.
Let’s consider a real-life example, where genes are embedded with traits for the next generation and every generation has their own traits which they transfer to the other generations with the help of Genes. Here we take a Genes class and one nested class Trait. Trait class has some traits like walk, hair and disease, and their values. These Genes will transfer to child class and child class may have some traits of its own and some inherit from its parent. This functionality can be implemented with the help of overriding nested class members.
('Diabetes', 'Migraine', 'TB') ('Typhoid', 'Diabetes', 'Migraine', 'TB')>
Note: Use Nested classes only if it is necessary, otherwise it will only make your code complex and difficult to debug.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Changing Class Members in Python
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Python | Check if a nested list is a subset of another nested list
- Method Overriding in Python
- Difference between Method Overloading and Method Overriding in Python
- Overriding the save method - Django Models
- Python | Pair and combine nested list to tuple list
- Python - Convert Lists to Nested Dictionary
- Python | Convert a nested list into a flat list
- Nested List Comprehensions in Python
- Python | Nested Dictionary
- Python | Intersection of two nested list
- Python | Sum values for each key in nested dictionary
- Python | Remove all duplicates and permutations in nested list
- Python | Convert list of nested dictionary into Pandas dataframe
- Python | Find maximum length sub-list in a nested list
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert nested dictionary into flattened dictionary
- Python | Remove duplicate dictionaries from nested dictionary
- Python | Convert given list into nested list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.