Answer to Question #246959 in C++ for Yashu

Question #246959
2. In Q1, add default as well as parameterized constructors in both base & derived class. Create object of Alarm_Clock class. Make it to call parameterized constructors of base as well as derived. Add destructors also. Check the order of destructors when derived class object goes out of scope.
1
Expert's answer
2021-10-05T23:13:50-0400
#include <iostream>
using namespace std;
class Base
{
   int m;


public:
   Base()
   {
      cout << "Default constructor in base\n";
   }
};


class Derived : public Base
{
   int n;


public:
   Derived()
   {
      cout << "Default constructor derived\n";
   }
   Derived(int i)
   {
      cout << "Parameterized constructor derived\n";
   }
};
class Alarm{
	public:
		~Alarm();//destructor
};
int main()
{
   Base z;
   Derived x1;
   Derived x2(4);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS