Last active
March 29, 2019 11:16
-
-
Save kateolenya/fd16273b5bf8a4c38703731aa2a81107 to your computer and use it in GitHub Desktop.
Basic example of inheritance in C++
This file contains 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 <iostream> | |
using namespace std; | |
class Device { | |
public: | |
int serial_number = 12345678; | |
void turn_on() { | |
cout << "Device is on" << endl; | |
} | |
private: | |
int pincode = 87654321; | |
}; | |
class Computer: public Device {}; | |
int main() { | |
Computer Computer_instance; | |
Computer_instance.turn_on(); | |
cout << "Serial number is: " << Computer_instance.serial_number << endl; | |
// cout << "Pin code is: " << Computer_instance.pincode << endl; | |
// will cause compile time error | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment