C++(Programming)
Description: Object Oriented Programming language objective questions | |
Number of Questions: 25 | |
Created by: Preeti Dasgupta | |
Tags: Inheritance Polymorphism objects classes Java/Oracle /C/C++ |
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.
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?
Which of the following is/are not manipulators in C++?
a) endl
b) setfill
c) setprecision
d) width
Which of the following operators cannot be overloaded using friend function? a) = b) -> c) [ ] d) -
Which of the following is not a characteristic of Object Oriented programming?
Which of the following keywords is/are not used in exception handling of C++?
a) try
b) throws
c) throw
d) catch
e) finally
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.
Which of the following is not an infinite loop?
What will be the output of the following program fragment?
#include<iostream.h> int i=10; int main() { int i=20; { int i=30; cout<<i<<::i; } return 0; }Function overloading: static polymorphism is achieved by function overloading. Which of the following is not allowed in function overloading?
Which of the following is not the characteristic of a constructor?
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;
The cin used as unformatted input is ___________.
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;
}
Templates are used _________.
What will be the order of execution of class constructors in following code? class alpha{ - - -}; class beta { - - -}; class gamma: public beta, public alpha{- - -};
Which of the following is not a file mode parameter used with open() function?
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?
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.
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.
What does the setbase manipulator do?
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; }
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
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.
_______ are used for distinctly separating the scopes of the declarations and definitions in a program where the name clashes are likely to occur.