Advertisement
ANCHI22

practice 1

Mar 29th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class A {
  4.     protected:
  5.           int v;
  6.     public:
  7.          A () {v = 0; };
  8.          void m1 () {
  9.              v += 10; m2 ();
  10.          };
  11.          void m2 () {
  12.              v += 20;
  13.          };
  14.          int getv () {
  15.              return v;
  16.          };
  17.     };
  18.     class B: public A {
  19.     public:
  20.     void m2 () {
  21.           v += 30;
  22.     };
  23. };
  24. int main (){
  25.     B * Obj = new B ();
  26.     Obj-> m1();
  27.     Obj-> m2();
  28.     cout << Obj-> getv () << endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement