C++(Programming)

Object Oriented Programming language objective questions

25 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Why is there a need for virtual base class in hybrid/diamond inheritance?
Multiple inheritance: more than one class is derived from single base class.
Multilevel inheritance: single class is derived from many base classes.

  1. To avoid ambiguity
  2. For reusability
  3. For faster processing
  4. None of the above
  5. All 1, 2 and 3
Question 2 Multiple Choice (Single Answer)

Operator overloading: the process in which operators are used to operate on different datatypes. For example, ‘+’ operator when used with integer of float, it does addition, while if it is used with character it does concatenation.
Which of the following operators cannot be overloaded?

  1. ?:
  2. =
  3. -
  4. ++
  5. No such operator exists
Question 3 Multiple Choice (Single Answer)

Which of the following is/are not manipulators in C++?
a) endl
b) setfill
c) setprecision
d) width

  1. Only d
  2. Both a and b
  3. None of these
  4. All are manipulators
  5. Both b and c
Question 4 Multiple Choice (Single Answer)

Which of the following operators cannot be overloaded using friend function?
a) =
b) ->
c) [ ]
d) -

  1. Both a and b
  2. Only b
  3. a, b and c
  4. All a, b, c and d
  5. Both b and d
Question 5 Multiple Choice (Single Answer)

Which of the following is not a characteristic of Object Oriented programming?

  1. Data is hidden and cannot be accessed by external functions.
  2. Follows bottom-up approach in program design.
  3. New data and functions cannot be added whenever necessary.
  4. Program is divided into what are known as objects.
  5. None of the above
Question 6 Multiple Choice (Single Answer)

Which of the following keywords is/are not used in exception handling of C++?
a) try
b) throws
c) throw
d) catch
e) finally

  1. Only e
  2. Both b and c
  3. Both b and e
  4. All keywords are used
  5. All a, c and d
Question 7 Multiple Choice (Single Answer)

What is the difference between function overloading and function overriding?
a) In overloading multiple functions are available with same name, while in overriding single function is rewritten.
b) Function overloading is possible in any program while function overriding is possible in inheritance.
c) In overriding both functions must have same signature. In overloading multiple functions have same name but different arguments.

  1. Only a
  2. Both a and b
  3. All a, b and c
  4. Both are same
  5. Both b and c
Question 8 Multiple Choice (Single Answer)

Which of the following is not an infinite loop?

  1. for(int i=1;;i++)
  2. for(int i=1;i<=10;)
  3. for(int i=4;i<5;i++)
  4. for(;;)
  5. none of the above
Question 9 Multiple Choice (Single Answer)

What will be the output of the following program fragment?<o:p>
#include<iostream.h><o:p>
int i=10;<o:p>
int main()<o:p>
{<o:p>
int i=20;<o:p>
{<o:p>
int i=30;<o:p>
cout<<i<<::i;<o:p>
}<o:p>
return 0;<o:p>
}<o:p>

  1. Prints 3020
  2. Prints 3010
  3. Will result in run time error
  4. Prints 3030
  5. None of the above
Question 10 Multiple Choice (Single Answer)

Function overloading: static polymorphism is achieved by function overloading.
Which of the following is not allowed in function overloading?

  1. Same function name with different number of arguments
  2. Same function name with different return type
  3. Same function name with different sequence of arguments
  4. Same function name with different types of arguments
  5. All of the above
Question 11 Multiple Choice (Single Answer)

Which of the following is not the characteristic of a constructor?

  1. Constructor has same name as that of the class.
  2. They don’t return value and are not of type void.
  3. Constructor can be private, public or protected.
  4. A class can have more than one constructor.
  5. None of the above
Question 12 Multiple Choice (Single Answer)

In which of the following code fragments the variable ‘x’ is evaluated to 810 int x;
a) x=32;
b) x=16;
c) x=38;
d) x=36;
x=x>>2; x=x>>1; x=x>>2; x=x>>2;

  1. Both a and b
  2. Both c and d
  3. Only a
  4. All codes
  5. None of the above
Question 13 Multiple Choice (Single Answer)

The cin used as unformatted input is ___________.

  1. Class defined in iostream.h header file.
  2. Object of the istream class.
  3. Package having different class definition.
  4. Function which is already defined.
  5. None of the above
Question 14 Multiple Choice (Single Answer)

What will be the output of array variable table after executing the following code?
include<iostream.h>
int main()
{
for(int j=0;j<3;j++)
{
for(int k=0;k<3;k++)
{
if(k==j)
table[j][k]=1;
else table[j][k]=0;
}
}
for(int i=0;i<3;i++)
{
for(int l=0;l<3;l++)
{
cout<<table[i][l] ;
}
cout<<endl;
}
return 0;
}

  1. 1 0 01 1 01 1 1
  2. 0 0 10 1 01 0 0
  3. 1 0 00 1 00 0 1
  4. 0 0 00 0 00 0 0
  5. None of the above
Question 15 Multiple Choice (Single Answer)

Templates are used _________.

  1. as decision making statement
  2. to achieve generic programming
  3. to reduce ambiguity
  4. to achieve polymorphism in C++
  5. none of the above
Question 16 Multiple Choice (Single Answer)

What will be the order of execution of class constructors in following code?
class alpha{ - - -};
class beta { - - -};
class gamma:
public beta,
public alpha{- - -};

  1. beta, alpha, gamma
  2. alpha, gamma , beta
  3. gamma , beta, alpha
  4. all of the above
  5. none of the above
Question 17 Multiple Choice (Single Answer)

Which of the following is not a file mode parameter used with open() function?

  1. ios::app
  2. ios::trunc
  3. ios::cur
  4. ios::ate
  5. none of the above
Question 18 Multiple Choice (Single Answer)

Why is there a need for virtual function when we access the function (having same name as that in base class) in derived class through the use of a pointer declared as pointer to the base class?

  1. We can not use the object name(with dot operator), as runtime polymorphism is achieved only when a virtual function is accessed through a pointer to the base class.
  2. We need to use single pointer variable to refer to the objects of different classes.
  3. When function is made virtual, C++ determines which function to use at run time based on the type of object pointed by the base class.
  4. All the above.
  5. None of these
Question 19 Multiple Choice (Single Answer)

What changes are to be made in prototype/signature of unary minus(-) operator overloading function to convert it into friend function?
Declaration : void operator –();
Definition :void space:: operator –(){ x=-x; y=-y;}; where space is class name and x and y are integer variables.

  1. Declaration : friend void operator –(space &s); Definition :void operator –(space &s){ s.x=-s.x; s.y=-s.y;}
  2. Declaration : friend void operator –(); Definition : void space operator –(){ x=-x; y=-y;}
  3. Declaration : friend void operator –(space &s); Definition : void operator –(space &s){ x=-x; y=-y;}
  4. Unary minus operator cannot be overloaded using friend function
  5. None of the above
Question 20 Multiple Choice (Single Answer)

What is/are the situation(s) where function is not treated as inline?
a) If the function contains recursion
b) If the function contains nested loop
c) If the function contains multiple decision making statement like switch
Inline function: whenever the function is called the function calling is replaced by function body.

  1. Only a
  2. Both a and b
  3. All a, b and c
  4. Both b and c
  5. None of the above
Question 21 Multiple Choice (Single Answer)

What does the setbase manipulator do?

  1. Sets the precision
  2. Sets the initial or basic value of variable
  3. Converts the data of one number system to another
  4. No such manipulator present in C++
  5. Sets the base type like decimal, binary, hexadecimal
Question 22 Multiple Choice (Single Answer)

What will be the output of following code?
class Base
{
public: void display()
{cout<<”t base d”;
}
virtual void show()
{
cout<<”t base s”;
}
};
Class Derived: public Base
{
public: void display()
{
cout<<”t derived d”;
}
void show()
{
cout<<”t derived s”; }
};
int main()
{
Base B;
Derived D;
Base *bptr;bptr=&B;
bptr->display();
bptr->show();
bptr=&D;
bptr-> display();
bptr-> show();
return 0;
}

  1. base d base s derived d derived s
  2. base d base s base d base s
  3. base d base s base d derived s
  4. none of the above
  5. all a, b and c
Question 23 Multiple Choice (Single Answer)

Consider the following code:
class A
{
int i1;
protected:int i2;
public:int i3;
};
class B:public A
{
Public:int i4;
};
class C:B{ };
The variable i2 is accessible

  1. To a public function in class A
  2. To a public function in class B
  3. To a public function in class C
  4. All of the above
  5. Both 1 and 2
Question 24 Multiple Choice (Single Answer)

If there is a pointer p to object of a base class and it contains the address of an object of derived class and both classes contain a virtual member function xyz(), then the statement p->xyz(); will cause the version of xyz() in the ___________ class to be executed.

  1. derived class
  2. base class
  3. produces compile time error
  4. produces runtime error
  5. none of the above
Question 25 Multiple Choice (Single Answer)

_______ are used for distinctly separating the scopes of the declarations and definitions in a program where the name clashes are likely to occur.<o:p>


  1. Virtual functions<o:p></o:p>

  2. templates<o:p></o:p>

  3. Namespaces<o:p></o:p>

  4. Inline function<o:p></o:p>
  5. None of above