Advertisement
AlexLeo

A Test of Ineritance & Access Modifiers in C++

Nov 6th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. class CClass
  6. {
  7. public:
  8.     int publicInt=1;
  9. protected:
  10.     int protectedInt=2;
  11. private:
  12.     int privateInt=3;
  13. };
  14.  
  15. class CClass2 : CClass
  16. {
  17. public:
  18.     int returnPublicInt()
  19.     {
  20.         return publicInt;
  21.     }
  22.  
  23.     int returnProtectedInt()
  24.     {
  25.         return protectedInt;
  26.     }
  27.     /*
  28.     int returnPrivateInt()
  29.     {
  30.         return privateInt;
  31.     }
  32.     */
  33. };
  34.  
  35. int main()
  36. {
  37.     CClass2 ccl1;
  38.  
  39.     cout << "publicInt=" << ccl1.returnPublicInt() << '\n';
  40.     cout << "protectedInt=" << ccl1.returnProtectedInt() << '\n';
  41.  
  42.     //system("pause");
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement