C++
[1] What are the two major components of the object?
Choice a
Data members
Choice b
member function
Choice c
Both i and ii[ans]
Choice d
None of the above
4] What is an anonymous class?
Choice a
Whenever a class is defined without any name.[ans]
Choice b
When structure is defined in a class
Choice c
When object is defined in a class.
Choice d
When template are defined in a class.
5] When does this pointer get created?
Choice a [ans]
The this pointer get created when a member function ( non static ) of class is
called.
Choice b
When constructor is called
Choice c
When destructor is called
Choice d
When constructor and destructor both are called.
6] What is the static variable in the class?
Choice a[ans]
The static variables are used to maintain values common on the entire class.
Choice b
It is like the private member class.
Choice c
It can declare outside the class.
Choice d
It can declare global to maintain constant value in program.
[7] What is an object?
Choice a
It is the data member of the class
Choice b
It is data member of structure
Choice c
It is instant of class[ans]
Choice d
It is the function of the class
] What is the difference between structure and class?
Choice a[ans]
The data member of strucure are by default public and the data members of the c
lass by default private
Choice b
The data member of structre are private and data members of class are public.
Choice c
The data members of both structure and class are by default public.
Choice d
The data members of both structure and class are by default private.
[9] How many access specifiers are there in C++?
Choice a
2
Choice b
1
Choice c
4
Choice d
3[ans]
10] Which of the following access specifiers are available in c++?
Choice a
Private
Choice b
Protected
Choice c
Public
Choice d [ans]
All the above
[11] The job of constructor is
Choice a[ans]
to initialize the objects of its class
Choice b
to declare the objects of its class
Choice c
to swap the objects
Choice d
None of the above
12] Constructor can be defined
Choice a[ans]
inside the class
Choice b
outside the class
Choice c
inside another class
Choice d
Both ( a ) and ( b )
[13] Constructors have the return type
Choice a
int
Choice b
void[ans]
Choice c
class
Choice d
None of the above
[14] In function overloading the functions have
Choice a
different number of arguments
Choice b
different types of argument
Choice c
different order of arguments
Choice d[ans]
All of the above
[15] _________ provides automatic initialization of objects.
Choice a
destructor
Choice b
member function
Choice c
constructor[ans]
Choice d
automatic initialization of objects is not allowed in C++
[16] Select the correct alternative for the following :
I ] Overloaded functions can return default values.
II ] Overloaded functions can also be written with the same prototype.
Choice a
true , false
Choice b
false , false
Choice c
false , true
Choice d
true , true
17] Following is/are the way/ways to pass the arguments to a function ?
Choice a
By value
Choice b
By address
Choice c
By reference
Choice d[ans]
All of the above
18] A class can contain multiple constructors.
Choice a
true[ans]
Choice b
false
Choice c
may be in certain cases only
Choice d
None of the above
[19] Which of the following operators can be overloaded?
Choice a
.(dot) and :: (scope resolution)
Choice b
?:
Choice c
new and delete [ans]
Choice d
None of the above
20] While overloading the operator, the operator function must be eithe _______
_________ .
Choice a
static function
Choice b
member function or friend function [ans]
Choice c
inline function
Choice d
overloaded funtion
[21] Friend function can access
Choice a
Private members of the class[ans]
Choice b
Protected members of the class
Choice c
Public members of the class
Choice d
All of the above
[22] Which of the following statement is correct
Choice a
Precedence cannot be changed through overloading
Choice b
Overloading is not allowed for user-defined types
Choice c
new and delete operator cannot be overloaded
Choice d
All of the above
[24] Consider following code snippet:
#include <iostream>
using namespace std ;
class test
{
int code ;
static int count ;
public:
void setcode ( void )
{
code = ++count ;
}
void showcode ( void )
{
cout << "object number:" << code << endl ;
}
static void showcount ( void )
{
cout << "count:" << count << endl ;
}
} ;
int test :: count ;
void main( )
{
test t1, t2 ;
t1.setcode ( ) ;
t2.setcode ( ) ;
test t3 ;
t3.setcode ( ) ;
t1.showcode ( ) ;
t2.showcode ( ) ;
t3.showcode ( ) ;
test::showcount ( ) ;
}
What wiuld be the output of the program?
Choice a [ans]
object number:1
object number:2
object number:3
count:3
Choice b
object number:3
object number:3
object number:3
count:3
Choice c
object number:2
object number:2
object number:2
count:0
Choice d
None of the above
26] Consider following code snippet:
#include <iostream>
using namespace std ;
class item
{
int number ;
float cost ;
public:
void getdata ( int a, float b ) ;
void putdata ( void )
{
cout << "number :" << number << endl ;
cout << "cost :" << cost << endl ;
}
} ;
void item :: getdata ( int a, float b )
{
number = a ;
cost = b ;
}
void main( )
{
item x ;
x.getdata ( 100,299.95 ) ;
x.putdata ( ) ;
item y;
y.getdata ( 200,175.50 ) ;
y.putdata ( ) ;
}
What would be the output of the above program?
Choice a
number :100
cost :299.95
Choice b
number :200
cost :175.5
Choice c
Both of the above[ans]
Choice d
None of the above
27] Consider following code snippet:
#include<iostream>
using namespace std ;
class sample
{
int a ;
int b ;
public:
void setvalue( )
{
a = 25 ; b = 40 ;
}
friend float mean ( sample ) ;
} ;
float mean ( sample s )
{
return float ( s.a + s.b ) / 2.0 ;
}
void main( )
{
sample X ;
X.setvalue ( ) ;
cout << "Mean Value - " << mean ( X ) << endl ;
}
What would be the output of the above program?
Choice a
Mean Value - 25
Choice b
Mean Value - 40
Choice c
Mean Value - 32.5 [ans]
Choice d
Mean Value - 65
29] Consider following code snippet:
#include <iostream>
using namespace std;
class ABC ;
class XYZ
{
int x ;
public:
void setvalue ( int i ) { x = i ; }
friend void max ( XYZ, ABC ) ;
} ;
class ABC
{
int a ;
public:
void setvalue ( int i )
{
a = i ;
}
friend void max ( XYZ, ABC ) ;
} ;
void max ( XYZ m, ABC n )
{
if ( m.x >= n.a )
cout << m.x ;
else
cout << n.a ;
}
void main( )
{
ABC abc ;
abc.setvalue ( 10 ) ;
XYZ xyz ;
xyz.setvalue ( 20 ) ;
max ( xyz, abc ) ;
}
What would be the output of the above program?
Choice a
10
Choice b
20
Choice c
10 20 [ans]
Choice d
15
30] Consider following code snippet:
#include <iostream>
using namespace std ;
class class_2 ;
class class_1
{
int value1 ;
public:
void indata ( int a ) { value1 = a ; }
void display ( void ) { cout << value1 << endl ; }
friend void exchange ( class_1 &, class_2 & ) ;
} ;
class class_2
{
int value2 ;
public:
void indata ( int a ) { value2 = a ; }
void display ( void ) { cout << value2 << endl ; }
} ;
void exchange ( class_1 & x, class_2 & y )
{
int temp = x.value1 ;
x.value1 = y.value2 ;
y.value2 = temp ;
}
void main( )
{
class_1 C1 ;
class_2 C2 ;
C1.indata ( 100 ) ;
C2.indata ( 200 ) ;
cout << "Values before exchange" << endl ;
C1.display ( ) ;
C2.display ( ) ;
exchange ( C1, C2 ) ;
cout << "Values after exchange" << endl ;
C1.display ( ) ;
C2.display ( ) ;
}
What would happened when the above code would be executed?
Choice a
Error: cannot access private members declared inside class 'class_2'[ans]
Choice b
Error: Declaration Syntax Error
Choice c
Error: 'Statement missing ;'
Choice d
None of the above