Created
September 5, 2018 17:03
-
-
Save dibakarsutradhar/991632f49dd474afe4bdea0e6e85d016 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
// C++ Inheritance | |
#include <iostream> | |
#include <bits/stdc++.h> | |
using namespace std; | |
// Base Class | |
class Parent{ | |
public: | |
int id_p; | |
}; | |
// Sub Class inhertiating from Base Class | |
class Child : public Parent { | |
public: | |
int id_c; | |
}; | |
// Main Function | |
int main() { | |
Child obj1; | |
// An object of class child has all data members and member functions of class Parent | |
obj1.id_c = 10; | |
obj1.id_p = 20; | |
cout << "Child id is: " << obj1.id_c << endl; | |
cout << "Parent id is: " << obj1.id_p << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment