Object Oriented Programming using C++ Quiz Questions with Answers


1)      How to create a dynamic array of pointers(to integers) of size 10 using new in C++?
a)       Int *arr=new int *[10];
b)      Int **arr=new int **[10];
c)       Int **arr=new int [10];
d)      Not possible

Answer is b



2)      #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;
}

a)       Compile error
b)      Base::fun(int i) called
Answer is B

We can access base class functions using scope resolution operator even if they are made hidden by a derived class function

3)      #include<iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
Base *bp=new Derived;
Derived *dp=new Base;
}
a)       No compile error
b)      Compile error
c)       Runtime error

Answer is  C

4)      Which of the following functions must use reference?
a)       Assignment operator function
b)      Copy constructor
c)       Destructor
d)      Parameterized constructor

Answer is  B

5)      Which of the following is FALSE about reference in C++
a)       References cannot be NULL
b)      A References must be initialized when declared
c)       Once a References is created ,it cannot be later made to References another object it cannot be reset
d)      References can’t refer to constant value

Answer is D

Comments