- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Overriding Methods in Python
You can always override your parent class methods. One reason for overriding parent's methods is because you may want special or different functionality in your subclass.
#!/usr/bin/python class Parent: # define parent class def myMethod(self): print 'Calling parent method' class Child(Parent): # define child class def myMethod(self): print 'Calling child method' c = Child() # instance of child c.myMethod() # child calls overridden method
When the above code is executed, it produces the following result −
Calling child method
- Overriding in C#
- Method overriding in Java
- Overriding in Java programming
- Method Overriding in Perl
- Dictionary Methods in Python
- List Methods in Python?
- Python String Methods ?
- Overriding Vs Shadowing in C#
- Method Overriding in Dart Programming
- Dictionary Methods in Python Program
- Base Overloading Methods in Python
- overriding method different package in java
- When Method Overriding occurs in Java?
- Function Overloading and Overriding in PHP
- Rules for Java method overriding