Show the output of the following code: #include <iostream> using namespace std;class Parent {public: Parent() {cout << "Parent's no-arg constructor is invoked" << end1; }~Parent() {cout << "Parent's destructor is invoked" << end1; }};class Child: public Parent {public: Child() {cout << "Child's no-arg constructor is invoked" << end1; }~Child() {cout << "Child's destructor is invoked" << end1; }};int main() {Child c1; Child c2;return 0; }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Show the output of the following code:
#include <iostream> using namespace std;
class Parent
{
public: Parent()
{
cout << "Parent's no-arg constructor is invoked" << end1;
}
~Parent()
{
cout << "Parent's destructor is invoked" << end1;
}
};
class Child: public Parent
{
public: Child()
{
cout << "Child's no-arg constructor is invoked" << end1;
}
~Child()
{
cout << "Child's destructor is invoked" << end1;
}
};
int main()
{
Child c1; Child c2;
return 0;
}
Step by step
Solved in 3 steps