62.
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
  string str = "HelloWorld!";
  cout<<str.capacity();
  cout<<str.size();
  return 0;
}

63.
What will be the output of the following C++ code?
#include <iostream> 
#include <string>
#include <cstring>
using namespace std; 
int main(int argc, char const *argv[])
{
	string s("a");
	cout<<s;
	return 0;
}

65.
What will be the output of the following C++ code?
#include <iostream> 
#include <string>
using namespace std; 
int main(int argc, char const *argv[])
{
	char s1[6] = "Hello";
	char s2[6] = "World";
	char s3[12] = s1 + " " + s2;
	cout<<s3;
	return 0;
}

68.
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
	static int a;
    public:
	A()
        {
		cout<<"Object of A is created\n";
	}
	void show()
        {
		a++;
		cout<<"a: "<<a<<endl;
	}
};
 
class B
{
    public:
};
 
int main(int argc, char const *argv[])
{
	A a1, a2;
	A a3 = a1 + a2;
	return 0;
}

69.

#include <iostream>
using namespace std;
class three_d 
{
    int x, y, z;
    public:
    three_d() { x = y = z = 0; }
    three_d(int i, int j, int k) { x = i; y = j; z = k; }
    three_d operator()(three_d obj);
    three_d operator()(int a, int b, int c);
    friend ostream &operator<<(ostream &strm, three_d op);
};
three_d three_d::operator()(three_d obj)
{
    three_d temp;
    temp.x = (x + obj.x) / 2;
    temp.y = (y + obj.y) / 2;
    temp.z = (z + obj.z) / 2;
    return temp;
}
three_d three_d::operator()(int a, int b, int c)
{
    three_d temp;
    temp.x = x + a;
    temp.y = y + b;
    temp.z = z + c;
    return temp;
}
    ostream &operator<<(ostream &strm, three_d op) {
    strm << op.x << ", " << op.y << ", " << op.z << endl;
    return strm;
}
int main()
{
    three_d objA(1, 2, 3), objB(10, 10, 10), objC;
    objC = objA(objB(100, 200, 300));
    cout << objC;
    return 0;
}

70.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class sample
{
    private:
    int* i;
    int j;
    public:
    sample (int j);
    ~sample ();
    int& operator [] (int n);
};
int& sample::operator [] (int n)
{
    return i[n];
}
sample::sample (int j)
{
    i = new int [j];
    j = j;
}
sample::~sample ()
{
    delete [] i;
}
int main ()
{
    sample m (5);
    m [0] = 25;
    m [1] = 20;
    m [2] = 15;
    m [3] = 10;
    m [4] = 5;
    for (int n = 0; n < 5; ++ n)
    cout << m [n];
    return 0;
}

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.