Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Device {
  5. public:
  6. int serial_number = 12345678;
  7.  
  8. void turn_on() {
  9. cout << "Device is on" << endl;
  10. }
  11. };
  12.  
  13. class Computer: private Device {
  14. public:
  15. void say_hello() {
  16. turn_on();
  17. cout << "Welcome to Windows 95!" << endl;
  18. }
  19. };
  20.  
  21. int main() {
  22. Device Unknown_device;
  23. Computer my_computer;
  24.  
  25. cout << "\t Unknown Device" << endl;
  26. cout << "Serial number is: "<< Unknown_device.serial_number << endl;
  27. Unknown_device.turn_on();
  28.  
  29. // cout << "Serial number is: " << my_computer.serial_number << endl;
  30. // my_computer.turn_on();
  31. // will cause compile time error
  32.  
  33. cout << "\t My computer" << endl;
  34. my_computer.say_hello();
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement