Tranvick

Example6

Jan 8th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. //Пример 6.Классы:
  2. //описание; члены класса; управление доступом; статичные поля и методы
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class MyClass {
  9. private:
  10.     int field1;
  11.     int method1() {
  12.         return 0;
  13.     }
  14. protected:
  15.     int field2;
  16.     void method2();
  17. public:
  18.     static int field3;
  19.     static void method3() {
  20.         cout << "I'm a static method\n";
  21.     }
  22. };
  23.  
  24. int MyClass :: field3 = 10;
  25.  
  26. void MyClass :: method2() {
  27.     cout << "I'm a protected non-static method\n";
  28. }
  29.  
  30. int main() {
  31.     MyClass :: method3();
  32.     MyClass t;
  33.     t.field3 = 10;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment