Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

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

Choice a
Choice b
Choice c
Choice d

2
1
4
3

[2] What is an object?


Choice a
Choice b
Choice c
Choice d

It is the data member of the class


It is data member of structure
It is instant of class
It is the function of the class

[3] What is the difference between structure and class?


Choi
ce a

The data member of strucure are by default public and the data
members of the class by default private

Choi
ce b

The data member of structre are private and data members of


class are public.

Choi
ce c

The data members of both structure and class are by default


public.

Choi
ce d

The data members of both structure and class are by default


private.

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


Choi
ce a

The static variables are used to maintain values common on


the entire class.

Choi
ce b

It is like the private member class.

Choi
ce c

It can declare outside the class.

Choi
ce d

It can declare global to maintain constant value in program.

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

Data members

Choice a

member function

Choice b

Both i and ii

Choice c

None of the above

Choice d

[6] How data hiding is possible within a class?


By private declaration

Choice a

By public declaration

Choice b

By protected declaration

Choice c

By friend declaration

Choice d

[7] What is encapsulation?


Choic
ea

Binding of data and function together into single entity.

Choic
eb

Binding data and class in single entity.

Choic
ec

Binding data and structure in single entity.

Choic
ed

Binding function and class in single entity.

[8] When does this pointer get created?


Choi
ce a

The this pointer get created when a member function ( non


static ) of class is called.

Choi
ce b

When constructor is called

Choi
ce c

When destructor is called

Choi
ce d

When constructor and destructor both are called.

[9] 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.

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


Private

Choice a

Protected

Choice b

Public

Choice c

All the above

Choice d

[11] In function overloading the functions have


different number of arguments

Choice a

different types of argument

Choice b

different order of arguments

Choice c

All of the above

Choice d

[12] Following is/are the way/ways to pass the arguments to a function ?


By value

Choice a

By address

Choice b

By reference

Choice c

All of the above

Choice d

[13] The job of constructor is


Choice a

to initialize the objects of its class

to declare the objects of its class

Choice b

to swap the objects

Choice c

None of the above

Choice d

[14] _________ provides automatic initialization of objects.


Choic
ea

destructor

Choic
eb

member function

Choic
ec

constructor

Choic
ed

automatic initialization of objects is not allowed in C++

[15] 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.
true , false

Choice a

false , false

Choice b

false , true

Choice c

true , true

Choice d

[16] Constructors have the return type


Choice a
Choice b
Choice c
Choice d

int
void
class
None of the above

[17] Constructor can be defined


Choice a

inside the class

outside the class

Choice b

inside another class

Choice c

Both ( a ) and ( b )

Choice d

[18] A class can contain multiple constructors.


Choice a
Choice b
Choice c
Choice d

true
false
may be in certain cases only
None of the above

[19] When an operator works on various type of operands is called


Choice a
Choice b
Choice c
Choice d

Operator overloading
Operator classification
Operator initialization
All of the above

[20] While overloading the operator, the operator function must be eithe
________________ .
Choice a
Choice b
Choice c
Choice d

static function
member function or friend function
inline function
overloaded funtion

[21] Which of the following operator cannot be overloaded by using friend


function?
Choice a

Assignment operator =

Choice b
Choice c
Choice d

Function call operator ( )


Both ( i ) and ( ii )
Conditional operator ? :

[22] Which of the following operator cannot be overloaded?


Choice a
Choice b
Choice c
Choice d

new
delete
?:
All of the above.

[23] 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
Both of the above

Choice c

None of the above

Choice d

[24] 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
Choice b
Choice c

T1 = 2hours and 45minutes


T2 = 3hours and 30minutes
T3 = 6hours and 15minutes

Choice d

All of the abov

[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

Choice b

Choice c

Choice d

object number:1
object number:2
object number:3
count:3
object number:3
object number:3
object number:3
count:3
object number:2
object number:2
object number:2
count:0
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
Choice b
Choice c
Choice d
[27] Consider following code snippet:
#include<iostream>
using namespace std ;
class sample
{
int a ;
int b ;
public:
void setvalue( )

67
88
Both of the above
77

{
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
Choice b
Choice c
Choice d

[28] Consider the floowing program


# include < iostream.h >
class Sample
{
int x , y , sum ;
Sample ( int a , int b = 2)
{
x=a;
y=b;
}

Mean Value - 25
Mean Value - 40
Mean Value - 32.5
Mean Value - 65

public :
void Display ( void )
{
cout << x << y << sum <<endl ;
}
};
void main ( void )
{
Sample p( 10 , 20 ) ;
p.Display ( ) ;
}
What would be the output of the above program ?
Choice a
Choice b
Choice c
Choice d

[29] 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;

10 20 30
10 2 12
10 22 32
Compile time Error

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( )
{
Mn;
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'

[30] 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
Choice b
Choice c
Choice d

10
20
10 20
15

You might also like