github

Made bySaurav Hathi

MCQ Test C/C++: Object Oriented Programming 2

Q1:

At which time does the static_cast can be applied?

Tags:
Section:
Core Programming
Options:
Q2:

When the inheritance is private, the private methods in base class are __________ in the derived class (in C++).

Tags:
Section:
Core Programming
Options:
Q3:

In C++, runtime polymorphism is achieved by

Tags:
Section:
Core Programming
Options:
Q4:

What is the syntax of friend function in C++?

Tags:
Section:
Core Programming
Options:
Q5:

What can be passed as a non-type template parameter during compile time?

Tags:
Section:
Core Programming
Options:
Q6:

From where is the template class derived?

Tags:
Section:
Core Programming
Options:
Q7:

Which keyword can be used in template in C++?

Tags:
Section:
Core Programming
Options:
Q8:

What is the output of this C++ program?

#include <iostream>

using namespace std;

namespace Box1

{

int a = 4;

}

namespace Box2

{

int a = 13;

}

int main ()

{

int a = 16;

Box1::a;

Box2::a;

cout << a;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q9:

What is the output of this C++ program?

#include <iostream>

using namespace std;

class rect

{

int x, y;

public:

void val (int, int);

int area ()

{

return (x * y);

}

};

void rect::val (int a, int b)

{

x = a;

y = b;

}

int main ()

{

rect rect;

rect.val (3, 4);

cout << "rect area: " << rect.area();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q10:

What is the output of this C++ program?

#include <iostream>

using namespace std;

class CDummy

{

public:

int isitme (CDummy& param);

};

int CDummy::isitme (CDummy& param)

{

if (&param == this)

return true;

else

return false;

}

int main ()

{

CDummy a;

CDummy *b = &a;

if (b->isitme(a))

{

cout << "execute";

}

else

{

cout<<"not execute";

}

return 0;

}

Tags:
Section:
Core Programming
Options:
Q11:

What will be the output of this C++ program?

#include <iostream>

using namespace std;

int i;

class A

{

public:

~A()

{

i=10;

}

};

int foo()

{

i=3;

A ob;

return i;

} 

int main()

{

cout << foo() << endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q12:

What will be the output of the following C++ program?

#include<iostream>

using namespace std;

class X

{

public:

int x;

};

int main()

{

X a = {10};

X b = a;

cout << a.x << " " << b.x;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q13:

What is the output of this C++ program(if size of int is 4 bytes)?

#include<iostream>

using namespace std;

class Test

{

static int x;

int *ptr;

int y;

}; 

int main()

{

Test t;

cout << sizeof(t) << " ";

cout << sizeof(Test *);

}

Tags:
Section:
Core Programming
Options:
Q14:

What is the output of the following C++ program?

#include <iostream>

using namespace std;

class Box

{

public :

double length;

double breadth;

double height;

};

int main( )

{

Box Box1;

double volume;

Box1.height = 5;

Box1.length = 6;

Box1.breadth = 7.1;

volume = Box1.height * Box1.length * Box1.breadth;

cout <<  volume <<endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q15:

What is the output of this C++ program?

#include <iostream>

using namespace std;

class Rect

{

int x, y;

public:

void set_values (int,int);

int area ()

{

return (x * y);

}

};

void Rect::set_values (int a, int b)

{

x = a;

y = b;

}

int main ()

{

Rect recta, rectb;

recta.set_values (5, 6);

rectb.set_values (7, 6);

cout << "recta area: " << recta.area();

cout << "rectb area: " << rectb.area();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q16:

What is the output of this C++ program?

#include <iostream>

using namespace std;

class sample

{

private:

int var;

public:

void input()

{

cout << var;

}

void output()

{

cout << "Variable entered is ";

cout << var << "\n";

}

};

int main()

{

sample object;

object.input();

object.output();

object.var();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q17:

What is the output of following C++ program?

#include<iostream>

using namespace std;

class Empty {};

int main()

{

cout << sizeof(Empty);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q18:

What is the output of this C++ program(If int size is 4 bytes)?

#include<iostream>

using namespace std;

class base {

int arr[10];

};

class b1: public base { };

class b2: public base { };

class derived: public b1, public b2 {};

int main(void)

{

cout << sizeof(derived);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q19:

What is the output of this C++ program?

#include<iostream>

using namespace std;

class P {

public:

void print()  { cout <<"Inside P"; }

}; 

class Q : public P {

public:

void print() { cout <<"Inside Q"; }

};

class R: public Q { };

int main(void)

{

R r;

r.print();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q20:

What is the output of this C++ program?

#include<iostream>

using namespace std;

class Base {};

class Derived: public Base {};

int main()

{

Base *bp = new Derived;

Derived *dp = new Base;

}

Tags:
Section:
Core Programming
Options: