42. Which keyword is used to make a class inheritable by other classes in C++?
43. What is the purpose of destructors in C++?
44. What will be the output of the following C++ code?
#include<iostream>
using namespace std;
class Base {
public:
Base()
{ cout<<"Constructing Base \n"; }
virtual~Base()
{ cout<<"Destructing Base \n"; }
};
class Derived: public Base {
public:
Derived()
{ cout<<"Constructing Derived \n"; }
~Derived()
{ cout<<"Destructing Derived \n"; }
};
int main(void)
{
Derived *d = new Derived();
Base *b = d;
delete b;
return 0;
}
#include<iostream>
using namespace std;
class Base {
public:
Base()
{ cout<<"Constructing Base \n"; }
virtual~Base()
{ cout<<"Destructing Base \n"; }
};
class Derived: public Base {
public:
Derived()
{ cout<<"Constructing Derived \n"; }
~Derived()
{ cout<<"Destructing Derived \n"; }
};
int main(void)
{
Derived *d = new Derived();
Base *b = d;
delete b;
return 0;
}
45. Which concept allows you to reuse the written code?
46. What is virtual inheritance?
47. How structures and classes in C++ differ?
48. Which of the following class allows to declare only one object of it?
49. Which of the following is correct about new and malloc?
i. new is an operator whereas malloc is a function
ii. new calls constructor malloc does not
iii. new returns required pointer whereas malloc returns void pointer and needs to be typecast
i. new is an operator whereas malloc is a function
ii. new calls constructor malloc does not
iii. new returns required pointer whereas malloc returns void pointer and needs to be typecast