Created
September 8, 2018 19:49
-
-
Save dibakarsutradhar/20b4b295ad365f2d5da594a6d7df1360 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
// Base Class | |
class Parent { | |
public: | |
void print(){ | |
cout << "Parent Print Function" << endl; | |
} | |
}; | |
// Derived Class | |
class Child : public Parent { | |
public: | |
// We're defining the same member function already exists in Parent | |
void print(){ | |
cout << "Child Print Function" << endl; | |
} | |
}; | |
// main function | |
int main() { | |
// Object of Parent Class | |
Parent obj1; | |
// Object of Child Class | |
Child obj2 = Child(); | |
// obj1 will now call the print() function from Parent Class | |
obj1.print(); | |
// obj2 now will override the print() function in Parent and call the print() function from Child | |
obj2.print(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment