github

Made bySaurav Hathi

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

Q1:

What is meant by template parameter in C++?

Tags:
Section:
Core Programming
Options:
Q2:

Which operator is used for input stream in C++?

Tags:
Section:
Core Programming
Options:
Q3:

How many kinds of entities are directly parameterized in C++ through templates?

Tags:
Section:
Core Programming
Options:
Q4:

How many kinds of template parameters are there in C++?

Tags:
Section:
Core Programming
Options:
Q5:

How many number of pointer (*) does C have against a pointer variable declaration?

Tags:
Section:
Core Programming
Options:
Q6:

What is the validity of template parameters in C++?

Tags:
Section:
Core Programming
Options:
Q7:

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

#include<iostream>

using namespace std;

class Base

{

public:

void show()

{

cout<<" In Base ";

}

};

class Derived: public Base

{

public:

int x;

void show()

{

cout<<"In Derived ";

}

Derived()

{

x = 10;

}

};

int main(void)

{

Base *bp, b;

Derived d;

bp = &d;

bp->show();

cout << bp->x;   

return 0;

}

Tags:
Section:
Core Programming
Options:
Q8:

What is the output of this C++ program?

#include <iostream>

using namespace std;

template<typename T>class clsTemplate

{

public:

T value;

clsTemplate(T i)

{

this->value = i;

}

void test()

{

cout << value << endl;

}

};

class clsChild : public clsTemplate<char>

{

public:

clsChild(): clsTemplate<char>( 0 )

{

}

clsChild(char c): clsTemplate<char>( c )

{   

}

void test2()

{

test();

}

};

int main()

{

clsTemplate <int> a( 42 );

clsChild b( 'A' );

a.test();

b.test();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q9:

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

#include<iostream>

using namespace std;

class Base

{

public:

int fun()  { cout << "Base::fun() called"; }

int fun(int i)  { cout << "Base::fun(int i) called"; }

};

class Derived: public Base

{

public:

int fun() {  cout << "Derived::fun() called"; }

};

int main()

{

Derived d;

d.fun(5);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q10:

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

#include<iostream>

using namespace std;

class Base {

public:

int fun()          {    cout << "Base::fun() called";     }

int fun(int i)     {   cout << "Base::fun(int i) called";  }

};

class Derived: public Base  {

public:

int fun()   {     cout << "Derived::fun() called";   }

}; 

int main()  {

Derived d;

d.Base::fun(5);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q11:

What is the output of following C++ program?

#include <iostream>

#include<string>

using namespace std;

class Base

{

public:

virtual string print() const

{

return "This is Base class";

}

};

class Derived : public Base

{

public:

virtual string print() const

{

return "This is Derived class";

}

};

void describe(Base p)

{

cout << p.print() << endl;

}

int main()

{

Base b;

Derived d;

describe(b);

describe(d);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q12:

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

#include<iostream>

using namespace std;

class Base

{

protected:

int a;

public:

Base() {a = 0;}

};

class Derived1:  public Base

{

public:

int c;

};

class Derived2:  public Base

{

public:

int c;

};

class DerivedDerived: public Derived1, public Derived2

{

public:

void show()  {   cout << a;  }

};

int main(void)

{

DerivedDerived d;

d.show();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q13:

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

#include<iostream>

using namespace std;

class Base1

{

public:

char c;

};

class Base2

{

public:

int c;

};

 

class Derived: public Base1, public Base2

{

public:

void show()  { cout << c; }

};

int main(void)

{

Derived d;

d.show();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q14:

What is the output of this C++ program?

#include <iostream>

using namespace std;

class Base

{

public:

Base(){}

~Base(){}

protected:

private:

};

class Derived:public Base

{

public:

Derived(){}

Derived(){}

private:

protected:

};

int main()

{

cout << "The program exceuted" << endl;

}

Tags:
Section:
Core Programming
Options:
Q15:

What is the output of this C++ program?

#include <iostream>

using namespace std;

template<typename type>

type Max(type Var1, type Var2)

{

return Var1 > Var2 ? Var1:Var2;

}

int main()

{

int p;

p = Max(100, 200);

cout << p << endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q16:

What is the output of this C++ program?

#include <iostream>

using namespace std;

template<typename type>

class Test

{

public:

Test()

{

};

∼Test()

{

};

type Funct1(type Var1)

{

return Var1;

}

type Funct2(type Var2)

{

return Var2;

}

};

int main()

{

Test<int> Var1;

Test<float> Var2;

cout << Var1.Funct1(200) << endl;

cout << Var2.Funct2(3.123) << endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q17:

What is the output of this C++ program?

#include <iostream>

using namespace std;

class class0

{

public:

virtual ∼class0(){ }

protected:

char p;

public:

char getChar();

};

class class1 : public class0

{

public:

void printChar();

};

void class1::printChar()

{

cout  << "True" << endl;

}

int main()

{

class1 c;

c.printChar();

return 1;

}

Tags:
Section:
Core Programming
Options:
Q18:

What is the output of this C++ program?

#include <iostream>

using namespace std;

template <class T>

class A

{

public:

A(int a): x(a) { }

protected:

int x;

};

template <class T>

class B: public A<char>

{

public:

B(): A<char>::A(100)

{

cout << x * 2 << endl;

}

};

int main()

{

B<char> test;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q19:

What is the output of this C++ program?

#include <iostream>

using namespace std;

template <class type>

class Test

{

public:

Test();

∼Test();

type Data(type);

};

template <class type>

type Test<type>::Data(type Var0)

{

return Var0;

}

template <class type>

Test<type>::Test()

{

}

template <class type>

Test<type>::~Test()

{

}

int main(void)

{

Test<char> Var3;

cout << Var3.Data('K') << endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q20:

What is the output of this C++ program?

#include <iostream>

using namespace std;

class Base

{

public:

Base ( )

{

cout << "1";

}

∼Base ( )

{

cout << "2";

}

};

class Derived : public Base

{

public:

Derived  ( )

{

cout << "3";

}

∼Derived ( )

{

cout << "4";

}   

};

int main( )

{

Derived x;

}

Tags:
Section:
Core Programming
Options: