31. Which keyword is used to make a member function constant in C++?
32. What is the difference between a constructor and a normal member function in C++?
33. What is the purpose of the keyword 'explicit' before a constructor in C++?
34. Which keyword is used to prevent inheritance in C++?
35. What is the access specifier that allows members of a class to be accessed from anywhere in the program in C++?
36. What is the difference between a shallow copy and a deep copy in C++?
37. What will be the output of the following C++ code?
#include <iostream>
#include <complex>
using namespace std;
int main ()
{
complex<double> mycomplex (20.0, 2.0);
cout << imag(mycomplex) << endl;
return 0;
}
#include <iostream>
#include <complex>
using namespace std;
int main ()
{
complex<double> mycomplex (20.0, 2.0);
cout << imag(mycomplex) << endl;
return 0;
}
38. How many parameters does a conversion operator may take?
39. What is operator overloading in C++?
40. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Integer
{
int i;
public:
Integer(int ii) : i(ii) {}
const Integer
operator+(const Integer& rv) const
{
cout << "operator+" << endl;
return Integer(i + rv.i);
}
Integer&
operator+=(const Integer& rv)
{
cout << "operator+=" << endl;
i += rv.i;
return *this;
}
};
int main()
{
int i = 1, j = 2, k = 3;
k += i + j;
Integer ii(1), jj(2), kk(3);
kk += ii + jj;
}
#include <iostream>
using namespace std;
class Integer
{
int i;
public:
Integer(int ii) : i(ii) {}
const Integer
operator+(const Integer& rv) const
{
cout << "operator+" << endl;
return Integer(i + rv.i);
}
Integer&
operator+=(const Integer& rv)
{
cout << "operator+=" << endl;
i += rv.i;
return *this;
}
};
int main()
{
int i = 1, j = 2, k = 3;
k += i + j;
Integer ii(1), jj(2), kk(3);
kk += ii + jj;
}
Read More Section(Classes and Objects in C plus plus)
Each Section contains maximum 100 MCQs question on Classes and Objects in C plus plus. To get more questions visit other sections.