C++ Programming - Constructors and Destructors
Exercise : Constructors and Destructors - Programs
- Constructors and Destructors - General Questions
- Constructors and Destructors - Programs
11.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
public:
IndiaBix(short ss)
{
cout<< "Short" << endl;
}
IndiaBix(int xx)
{
cout<< "Int" << endl;
}
IndiaBix(char ch)
{
cout<< "Char" << endl;
}
~IndiaBix()
{
cout<< "Final";
}
};
int main()
{
IndiaBix *ptr = new IndiaBix('B');
return 0;
}
12.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
public:
IndiaBix(short ss)
{
cout<< "Short" << endl;
}
IndiaBix(int xx)
{
cout<< "Int" << endl;
}
IndiaBix(float ff)
{
cout<< "Float" << endl;
}
~IndiaBix()
{
cout<< "Final";
}
};
int main()
{
IndiaBix *ptr = new IndiaBix('B');
return 0;
}
13.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
BixBase()
{
cout<< "Base OK. ";
}
~BixBase()
{
cout<< "Base DEL. ";
}
};
class BixDerived: public BixBase
{
public:
BixDerived()
{
cout<< "Derived OK. ";
}
~BixDerived()
{
cout<< "Derived DEL. ";
}
};
int main()
{
BixBase *basePtr = new BixDerived();
delete basePtr;
return 0;
}
14.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
BixBase()
{
cout<< "Base OK. ";
}
virtual ~BixBase()
{
cout<< "Base DEL. ";
}
};
class BixDerived: public BixBase
{
public:
BixDerived()
{
cout<< "Derived OK. ";
}
~BixDerived()
{
cout<< "Derived DEL. ";
}
};
int main()
{
BixBase *basePtr = new BixDerived();
delete basePtr;
return 0;
}
15.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
int x, y;
BixBase(int xx = 0, int yy = 5)
{
x = ++xx;
y = --yy;
}
void Display()
{
cout<< --y;
}
~BixBase(){}
};
class BixDerived : public BixBase
{
public:
void Increment()
{
y++;
}
void Display()
{
cout<< --y;
}
};
int main()
{
BixDerived objBix;
objBix.Increment();
objBix.Display();
return 0;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers