A. unexpected handler called
C. caught other exception
D. both unexpected handler called & caught bad_exception
Correct Answer is : both unexpected handler called & caught bad_exception
6. What is the output of the following C++ code?
#include
#include
using namespace std;
class A
{
float d;
public:
A(){
cout<<"Constructor of class A\n";
}
};
class B: public A
{
int a = 15;
public:
B(){
cout<<"Constructor of class B\n";
}
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}
C. exception occured: exiting
Correct Answer is : exception occured: exiting
7. What is a virtual function in C++?
A. caught other exception
D. both caught int & unexpected called
Correct Answer is : both caught int & unexpected called
8. Which is the correct syntax of declaring a virtual function?
C. both throwing & terminate
Correct Answer is : terminate
9. What is the output of the following C++ code?
#include
#include
using namespace std;
class A
{
float d;
public:
virtual void func(){
cout<<"Hello this is class A\n";
}
};
class B: public A
{
int a = 15;
public:
void func(){
cout<<"Hello this is class B\n";
}
};
int main(int argc, char const *argv[])
{
A *a;
a->func();
return 0;
}
Correct Answer is : unhandled
10. What is the output of the following C++ code?
#include
#include
using namespace std;
class A
{
float d;
public:
virtual void func(){
cout<<"Hello this is class A\n";
}
};
class B: public A
{
int a = 15;
public:
void func(){
cout<<"Hello this is class B\n";
}
};
int main(int argc, char const *argv[])
{
A *a = new A();
B b;
a = &b;
a->func();
return 0;
}
11. Which statement is incorrect about virtual function.
Correct Answer is : ofstream
12. The concept of deciding which function to invoke during runtime is called ______________________
Correct Answer is : fstream
13. What is a pure virtual function?
Correct Answer is : ios::trunc
14. What is the output of the following C++ code?
#include
#include
using namespace std;
class Mammal
{
public:
Mammal(){
cout<<"I'm a Mammal\n";
}
~Mammal(){}
};
class Human: public Mammal
{
public:
Human(){
cout<<"I'm a Human\n";
}
~Human(){}
};
class Male: public Human
{
public:
Male(){
cout<<"I'm a Male\n";
}
~Male(){}
};
class Female: public Human
{
public:
Female(){
cout<<"I'm a Female\n";
}
~Female(){}
};
int main(int argc, char const *argv[])
{
Male M;
return 0;
}
Correct Answer is : 45294
15. What is the order of Constructors call when the object of derived class B is declared, provided class B is derived from class A?
16. What is the order of Destructors call when the object of derived class B is declared, provided class B is derived from class A?
A. To open a file in input mode
B. To open a file in output mode
C. To truncate an existing file to half
D. To truncate an existing file to zero
Correct Answer is : To truncate an existing file to zero
17. What is the output of the following C++ Code?
#include
#include
using namespace std;
class Mammal
{
public:
virtual void Define(){
cout<<"I'm a Mammal\n";
}
};
class Human: public Mammal
{
public:
void Define(){
cout<<"I'm a Human\n";
}
};
class Male: public Human
{
public:
void Define(){
cout<<"I'm a Male\n";
}
};
class Female: public Human
{
public:
void Define(){
cout<<"I'm a Female\n";
}
};
int main(int argc, char const *argv[])
{
Mammal *M;
Male m;
Female f;
*M = m;
M->Define();
return 0;
}
Correct Answer is : ios::out
18. What is the output of the following C++ code?
#include
#include
using namespace std;
class Mammal
{
public:
virtual void Define(){
cout<<"I'm a Mammal\n";
}
};
class Human: public Mammal
{
public:
void Define(){
cout<<"I'm a Human\n";
}
};
class Male: public Human
{
public:
void Define(){
cout<<"I'm a Male\n";
}
};
class Female: public Human
{
public:
void Define(){
cout<<"I'm a Female\n";
}
};
int main(int argc, char const *argv[])
{
Mammal *M = new Mammal();
Male m;
Female f;
*M = m;
M->Define();
M = &m;
M->Define();
return 0;
}
19. Virtual functions in C++ tells the compiler to perform ______________________ on such functions.
Correct Answer is : ios::set
20. What is the output of the following C++ code?
#include
#include
using namespace std;
class Mammal
{
public:
virtual void Define(){
cout<<"I'm a Mammal\n";
}
};
class Human: public Mammal
{
private:
void Define(){
cout<<"I'm a Human\n";
}
};
int main(int argc, char const *argv[])
{
Mammal *M = new Mammal();
Human H;
M = &H;
M->Define();
return 0;
}
Correct Answer is : ios::in