
- Functional Programming Tutorial
- Home
- Introduction
- Functions Overview
- Function Types
- Call By Value
- Call By Reference
- Function Overloading
- Function Overriding
- Recursion
- Higher Order Functions
- Data Types
- Polymorphism
- Strings
- Lists
- Tuple
- Records
- Lambda Calculus
- Lazy Evaluation
- File I/O Operations
- Functional Programming Resources
- Quick Guide
- Useful Resources
- Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Function Overriding
When the base class and derived class have member functions with exactly the same name, same return-type, and same arguments list, then it is said to be function overriding.
Function Overriding using C++
The following example shows how function overriding is done in C++, which is an objectoriented programming language −
#include <iostream> using namespace std; class A { public: void display() { cout<<"Base class"; } }; class B:public A { public: void display() { cout<<"Derived Class"; } }; int main() { B obj; obj.display(); return 0; }
It will produce the following output
Derived Class
Function Overriding using Python
The following example shows how to perform function overriding in Python, which is a functional programming language −
class A(object): def disp(self): print "Base Class" class B(A): def disp(self): print "Derived Class" x = A() y = B() x.disp() y.disp()
It will produce the following output −
Base Class Derived Class
Advertisements