Sie sind auf Seite 1von 10

[1] What is the static variable in the class?

Choice a
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.

[2] How many access specifiers are there in C++?

Choice a
2
Choice b
1
Choice c
4
Choice d
3
[3] When does this pointer get created?
Choice a
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.
[4] What is an anonymous class?

Choice a
Whenever a class is defined without any name.
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] How data hiding is possible within a class?
Choice a
By private declaration
Choice b
By public declaration
Choice c
By protected declaration
Choice d
By friend declaration



[6] What are the two major components of the object?

Choice a
Data members
Choice b
member function
Choice c
Both i and ii
Choice d
None of the above


[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
Choice d
It is the function of the class

[8] What is encapsulation?
Choice a
Binding of data and function together into single entity.
Choice b
Binding data and class in single entity.
Choice c
Binding data and structure in single entity.
Choice d
Binding function and class in single entity.
[9] What is the difference between structure and class?
Choice a
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.

[10] Which of the following access specifiers are available in c++?

Choice a
Private
Choice b
Protected
Choice c
Public
Choice d
All the above



[11] Constructor can be defined
Choice a
inside the class
Choice b
outside the class
Choice c
inside another class
Choice d
Both ( a ) and ( b )

[12] 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
All of the above

[13] _________ provides automatic initialization of objects.
Choice a
destructor
Choice b
member function
Choice c
constructor
Choice d
automatic initialization of objects is not allowed in C++

[14] The job of constructor is
Choice a
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

[15] 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
All of the above


[16] Constructors have the return type
Choice a
int
Choice b
void
Choice c
class
Choice d
None of the above

[17] 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

[18] A class can contain multiple constructors.
Choice a
true
Choice b
false
Choice c
may be in certain cases only
Choice d
None of the above

[18] A class can contain multiple constructors.
Choice a
true
Choice b
false
Choice c
may be in certain cases only
Choice d
None of the above

[20] Which of the following operator cannot be overloaded by using friend func
tion?
Choice a
Assignment operator =
Choice b
Function call operator ( )
Choice c
Both ( i ) and ( ii )
Choice d
Conditional operator ? :
[21] When an operator works on various type of operands is called
Choice a
Operator overloading
Choice b
Operator classification
Choice c
Operator initialization
Choice d
All of the above

[22] Which of the following operator cannot be overloaded?
Choice a
new
Choice b
delete
Choice c
?:
Choice d
All of the above.

[23] Consider following code snippet:
#include <iostream>
using namespace std ;
class time
{
int hours ;
int minutes ;
public:
void gettime ( int h, int m )
{
hours = h ; minutes = m ;
}
void puttime ( void )
{
cout << hours << "hours and" ;
cout << minutes << "minutes" << endl ;
}
void sum ( time, time ) ;
} ;
void time :: sum ( time t1, time t2 )
{
minutes = t1.minutes + t2.minutes ;
hours = minutes / 60 ;
minutes = minutes % 60 ;
hours = hours + t1.hours + t2.hours ;
}
void main( )
{
time T1, T2, T3 ;
T1.gettime ( 2, 45 ) ;
T2.gettime ( 3, 30 ) ;
T3.sum (T1,T2) ;
cout << "T1 = " ; T1.puttime();
cout << "T2 = " ; T2.puttime();
cout << "T3 = " ; T3.puttime();
}

What would be the output of the above program?

Choice a
T1 = 2hours and 45minutes
Choice b
T2 = 3hours and 30minutes
Choice c
T3 = 6hours and 15minutes
Choice d
All of the above

[24] 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
Choice d
None of the above

[25] 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
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 set
{
int m, n ;
public:
void input ( void ) ;
void display ( void ) ;
int largest ( void ) ;
} ;
int set :: largest ( void )
{
if ( m >= n )
return m ;
else
return n ;
}
void set :: input ( void )
{
cout << "Input values of m and n" << endl ;
cin >> m >> n ;
}
void set :: display ( void )
{
cout << largest( ) << endl ;
}
void main( )
{
set A ;
A.input ( ) ;
A.display ( ) ;
}
What would be the output of the above program if we input the numer 67 and 88 to
the program?

Choice a
67
Choice b
88
Choice c
Both of the above
Choice d
77
[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
Choice d
Mean Value - 65


[28] Select the correct alternative for following
I ] All functions can be overloaded.
II ] Inline constructors can be overloaded.

Choice a
true , false
Choice b
false , false
Choice c
false , false
Choice d
true , true
[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
Choice d
15
[30] Consider following code snippet:
#include <iostream>
using namespace std;
class M
{
int x ;
int y ;
public:
void set_xy ( int a, int b )
{
x = a ;
y = b ;
}
friend int sum ( M m ) ;
} ;
int sum ( M m )
{
int M :: *px = &M :: x ;
int M :: *py = &M :: y ;
M *pm = &m ;
int S = m.px + pm->*py ;
return S ;
}
void main( )
{
M n ;
void ( M :: *pf ) ( int, int ) = &M :: set_xy ;
( n.*pf ) ( 10, 20 ) ;
cout << "SUM = " << sum ( n ) << endl ;
M *op = &n ;
( op -> *pf ) ( 30, 40 ) ;
cout << "SUM = " << sum ( n ) << endl ;
}
What would happen when the above code would get executed?
Choice a
Error:' Void function returning a value'
Choice b
Error:'px' is not a member function of 'M'
Choice c
Error:Syntax Error : identifier 'M'
Choice d
Error:'Member function defined in unnamed class'

Das könnte Ihnen auch gefallen