Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Пример 6.Классы:
- //описание; члены класса; управление доступом; статичные поля и методы
- #include <iostream>
- using namespace std;
- class MyClass {
- private:
- int field1;
- int method1() {
- return 0;
- }
- protected:
- int field2;
- void method2();
- public:
- static int field3;
- static void method3() {
- cout << "I'm a static method\n";
- }
- };
- int MyClass :: field3 = 10;
- void MyClass :: method2() {
- cout << "I'm a protected non-static method\n";
- }
- int main() {
- MyClass :: method3();
- MyClass t;
- t.field3 = 10;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment