Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. How many Destructors are allowed in a Class?
Correct Answer is : 2
2. What is the output of the following C++ code?
#include
#include
using namespace std;
class A{
mutable int a;
public:
A(){
cout<<"A's Constructor called\n";
}
~A(){
cout<<"A's Destructor called\n";
}
};
class B{
A a;
public:
B(){
cout<<"B's Constructor called\n";
}
~B(){
cout<<"B's Destructor called\n";
}
};
int main(int argc, char const *argv[])
{
B b1;
}
Correct Answer is : Static polymorphism
3. What is the output of the following C++ code?
#include
#include
using namespace std;
class A{
mutable int a;
public:
A(){
cout<<"A's Constructor called\n";
}
~A(){
cout<<"A's Destructor called\n";
}
};
class B: public A{
public:
B(){
cout<<"B's Constructor called\n";
}
~B(){
cout<<"B's Destructor called\n";
}
};
int main(int argc, char const *argv[])
{
B b1;
}
Correct Answer is : Dynamic polymorphism
4. What is the output of the following C++ code?
#include
#include
using namespace std;
class A{
mutable int a;
public:
A(){
cout<<"A's Constructor called\n";
}
~A(){
cout<<"A's Destructor called\n";
}
};
class B: public A{
A a;
public:
B(){
cout<<"B's Constructor called\n";
}
~B(){
cout<<"B's Destructor called\n";
}
};
int main(int argc, char const *argv[])
{
B b1;
}
Correct Answer is : In static polymorphism, the conflict between the function call is resolved during the compile time
5. What is the output of the following C++ code?
#include
#include
using namespace std;
class A{
mutable int a;
public:
A(){
cout<<"A's Constructor called\n";
}
~A(){
cout<<"A's Destructor called\n";
}
};
class B{
static A a;
public:
B(){
cout<<"B's Constructor called\n";
}
~B(){
cout<<"B's Destructor called\n";
}
};
int main(int argc, char const *argv[])
{
B b1;
}
Correct Answer is : In dynamic polymorphism, the conflict between the function call is resolved during the run time
6. What is the output of the following C++ code?
#include
#include
using namespace std;
class A{
mutable int a;
public:
A(){
cout<<"A's Constructor called\n";
}
~A(){
cout<<"A's Destructor called\n";
}
};
class B{
static A a;
public:
B(){
cout<<"B's Constructor called\n";
}
~B(){
cout<<"B's Destructor called\n";
}
};
A B::a;
int main(int argc, char const *argv[])
{
return 0;
}
Correct Answer is : i only
7. Which of the following represents the correct explicit call to a constructor of class A?
class A{
int a;
public:
A(int i)
{
a = i;
}
}
Correct Answer is : std is a standard namespace in C++
8. Which of the following constructors are provided by the C++ compiler if not defined in a class?
Correct Answer is : Compile-time error
9. When a copy constructor is called?
Correct Answer is : namespace::member
10. What is the output of following C++ code?
#include
using namespace std;
class A{
A(){
cout<<"Constructor called";
}
};
int main(int argc, char const *argv[])
{
A a;
return 0;
}
Correct Answer is : Neither code 1 nor code 2
11. What is the output of the following C++ code?
#include
using namespace std;
class A{
public:
A(){
cout<<"Constructor called";
}
};
int main(int argc, char const *argv[])
{
A *a;
return 0;
}
Correct Answer is : Error in C++ but Warning in C
12. What is the output of the following C++ code?
#include
using namespace std;
class A{
public:
int a;
};
int main(int argc, char const *argv[])
{
A a1 = {10};
A a2 = a1;
cout<
Correct Answer is : Error in C++ but Warning in C
13. What is the output of the following C++ code?
#include
using namespace std;
class A{
public:
int a;
A(int a){
this->a = a;
}
};
int main(int argc, char const *argv[])
{
A a1, a2(10);
cout<
Correct Answer is : Error in C++ and successful execution in C
14. What is the output of the following C++ code?
#include
using namespace std;
class A{
public:
int a;
A(int a=0){
this->a = a;
}
};
int main(int argc, char const *argv[])
{
A a1, a2(10);
cout<
Correct Answer is : Error in C++ and successful execution in C
15. What is the output of the following C++ code?
#include
using namespace std;
class A{
public:
int a;
A(){
cout<<"Constructor called";
}
};
int main(int argc, char const *argv[])
{
A *a1 = (A*)malloc(sizeof(A));
return 0;
}
Correct Answer is : Error in C++ and successful execution in C
16. What is the output of the following C++ code?
#include
using namespace std;
class A{
public:
int a;
A(){
cout<<"Constructor called";
}
} a;
int main(int argc, char const *argv[])
{
return 0;
}
Correct Answer is : Error in C++ and successful execution in C
17. What is the output of the following C++ code?
#include
using namespace std;
class A{
public:
int a;
A(){
cout<<"Constructor called\n";
}
} a;
int main(int argc, char const *argv[])
{
cout<<"Main function\n";
return 0;
}
Correct Answer is : Error in both C and C++
18. What is the output of the following C++ code?
#include
using namespace std;
class A{
A(){
cout<<"A's Constructor called\n";
}
};
class B
{
public:
A a;
B(){
cout<<"B's constructor called\ns";
}
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}
Correct Answer is : Error in C++ and Outputs Hello twice in C
19. What is the output of the following C++ code?
#include
using namespace std;
class A{
A(){
cout<<"A's Constructor called\n";
}
friend class B;
};
class B
{
public:
A a;
B(){
cout<<"B's constructor called\ns";
}
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}
Correct Answer is : bool
20. What is the output of the following C++ code?
#include
using namespace std;
class A{
~A(){}
};
class B
{
public:
A a;
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}