Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class A{
- protected:
- int x;
- };
- class B : public A{
- public:
- B()
- {
- x = 5;
- }
- };
- class C {
- protected:
- int y;
- public:
- C()
- {
- y = 8;
- }
- };
- class D : public B,C {
- public:
- void sum ()
- {
- cout<<"sum is "<<x+y<<endl;
- }
- };
- int main()
- {
- D obj; // created object of D class
- obj.sum();
- return 0;
- }
- // sum is 13
Advertisement
Add Comment
Please, Sign In to add comment