Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

Which of the following is not the member of class?

A. Static function

B. Friend function

C. Const function

D. Virtual function

ANSWER: B

Which of the following is not a type of constructor?

A. Copy constructor

B. Friend constructor

C. Default constructor

D. Parameterized constructor

ANSWER: B

cout is a/an __________ .

A. operator

B. function

C. object

D. macro

ANSWER: C

Which of the following concepts meANSWER wrapping up of data and functions together?

A. Abstraction

B. Encapsulation

C. Inheritance

D. Polymorphism

ANSWER: B

Which of the following operator is overloaded for object cout?

A. >>

B. <<
C. +

D. =

ANSWER: B

Which of the following is the correct class of the object cout?

A. iostream

B. istream

C. ostream

D. ifstream

ANSWER: C

Which of the following is correct about the statements given below? I. All operators can be
overloaded in C++. II. We can change the basic meaning of an operator in C++.

A. Only I is true.

B. Both I and II are false.

C. Only II is true.

D. Both I and II are true.

ANSWER: B

Which of the following operators cannot be overloaded?

A. []

B. ->

C. ?:

D. *

ANSWER: C

Which of the following header file includes definition of cin and cout?

A. istream.h

B. ostream.h

C. iomanip.h

D. iostream.h
ANSWER: D

Which of the following keyword is used to overload an operator?

A. overload

B. operator

C. friend

D. override

ANSWER: B

Which of the following is an invalid visibility label while inheriting a class?

A. public

B. private

C. protected

D. friend

ANSWER: D

Which of the following access specifier is used as a default in a class definition?

A. protected

B. public

C. private

D. friend

ANSWER: C

What is correct about the static data member of a class?

A. A static member function can access only static data members of a class.

B. A static data member is shared among all the object of the class.

C. A static data member can be accessed directly using class name in main().

D. Both A and B.

ANSWER: D

Which of the following keywords is used to control access to a class member?


A. Default

B. Break

C. Protected

D. Asm

ANSWER: C

Which of the following can access private data members or member functions of a class?

A. Any function in the program.

B. All global functions in the program.

C. Any member function of that class.

D. Only public member functions of that class.

ANSWER: C

Which of the following type of data member can be shared by all instances of its class?

A. Public

B. Inherited

C. Static

D. Friend

ANSWER: C

Overloaded functions are

A. Very long functions that can hardly run

B. One function containing another one or more functions inside it.

C. Two or more functions with the same name but different number of parameters or type.

D. none of the mentioned

ANSWER: C

How many number of spaces should be set in default tab?

A. 1

B. 2

C. 3
D. 4

ANSWER: D

Which function allows you to set minimum width for the next input?

A. setfill

B. setw

C. setwidth

D. None of the mentioned

ANSWER: B

Which of the following is a correct comment?

A. */ Comments */

B. ** Comment **

C. /* Comment */

D. { Comment }

ANSWER: C

Which of the following is known as insertion operator?

A. ^

B. v

C. <<

D. >>

ANSWER: C

Which of the following is extraction operator in C++?

A. ^

B. v

C. <<

D. >>

ANSWER: D
which of the following is input statement in C++?

A. cin

B. input

C. get

D. none of above

ANSWER: A

Which of the following is output statement in C++?

A. print

B. write

C. cout

D. cin

ANSWER: C

Regarding the use of new line character (/n) and endl manipulator with cout statement

A. Both ways are exactly same

B. Both are similar but endl additionally performs flushing of buffer

C. endl can’t be used with cout

D. \n can’t be used with cout

ANSWER: B

The operator that cannot be overloaded is

A. +

B. ::

C. -

D. ~

ANSWER: B

A static function

A. should be called when an object is destroyeD.

B. is closely connected with and individual object of a class.


C. can be called using the class name and function name.

D. is used when a dummy object must be created

ANSWER: C

We can output text to an object of class ostreamusing the insertion operator<< because

A. the ostream class is a stream

B. the insertion operator works with all classes.

C. we are actually outputting to cout.

D. the insertion operator is overloaded in ostream.

ANSWER: D

A white space is :

A. blank space

B. new line

C. tab

D. all of the above

ANSWER: D

n access control in a protected derivation, visibility modes will change as follows:

A. private, public and protected become protected

B. only public becomes protecteD.

C. public and protected become protecteD.

D. only private becomes protecteD.

ANSWER: C

For reading with cin object, we need to include __________file.

A. conio.h

B. fstream.h

C. stdio.h

D. iostream.h

ANSWER: D
Statement cin >> ch ; will start executing when we press _______ key.

A. any

B. any character

C. only character

D. escape

E. enter

ANSWER: E

You have a variable myNum that has the value 5. You want to print your variable to screen. How
would you do it?

A. cout<< "My number is", myNum << endl;.

B. cout<< "My number is 5" << endl;.

C. cout<< My number is << myNum << endl;.

D. cout<< "My number is" << myNum << endl;.

ANSWER: D

The file iostream includes________________.

A. the declarations of the basic standard input-output library.

B. the streams of includes and outputs of program effect.

C. mathematical functions are included

D. string functions are included

ANSWER: A

Which of the following is an escape sequence?

A. \c

B. \m

C. \f

D. \g

ANSWER: C
Which of the following is not an escape sequence?

A. \x

B. \y

C. \t

D. \\

ANSWER: B

cout is a/an __________ .

A. operator

B. function

C. object

D. macro

ANSWER: C

How to insert values in array of objects using new for an array int a[] at position n

A. a[n] = new int[n]

B. a[n] = new int[n-1]

C. a[n] = new int[n+1]

D. None of these

ANSWER: A

Suppose we have a class Weather and array of objects called w of size 10 i.e.,Weather w[10]. How to
delete memory of certain object at position say 'i'?

A. renew w[i]

B. ~Weather(i)

C. delete w[i];

D. All of these

ANSWER: C

What is the difference between? add_one(a) add_one(&a)


A. We pass address and value respectively

B. We pass value and address respectively

C. We pass values to both

D. We pass addresses to both

ANSWER: B

int *ptr[5];

A. a pointer of 5 int elements

B. an array of 5 int pointers

C. an array of 5 elements returning an int value

D. none of above

ANSWER: A

If the class Shape is an abstract class, what type of variable may be declared of the type Shape?

A. No variables must be declared because it is an abstract class

B. Only arrays of the Class shape may be declared

C. Objects of the class shape may be declared only if object of a class that is derived from Shape is
also declared

D. A pointer of the abstract class may be declared

ANSWER: D

What will be the output of the following code: inline double cube(double a) { return(a*a*a); } The
above inline function can be invoked by the statements like d=cube(2.5+1.5);

A. 64

B. 27

C. can predict

D. none of the above

ANSWER: A

Characteristics of static member variable

A. It is initialized to zero when the first object of its class is created.

B. It is visible only within the class , but its lifetime is the entire program
C. Only one copy of that member is created for the entire class and is shared by all the object of that
class.

D. All of the above

ANSWER: D

What happens when a class with parametrized constructor and having no default constructor is used
in the program and we create an object that needs a zero argument constructor

A. Compile time error

B. Preprocessing error

C. Runtime error

D. Runtime exeption

ANSWER: A

Which of the following are true

I. They should be declared in the public section

II. They are invoked automatically when the objects are created

III. They do not have any return type, not even void

IV. We cannot refer their addresses

V. Constructors cannot be virtual

A. I,II,III,V

B. II,III,IV,V

C. I,III,IV,V

D. I,II,III,IV,V

ANSWER: D

The private members of a class implement the OOP concept of

A. Data abstraction

B. Data hiding

C. Message passing

D. None of the above

ANSWER: B
A destructor

A. Has same name as that of class but preceded by a tilde

B. Does not take any argument

C. Does not return any value

D. All of the above

ANSWER: D

Which rule will not affect the friend function?

A. private and protected members of a class cannot be accessed from outside

B. private and protected member can be accessed anywhere

C. both a & b

D. None of the above

ANSWER: A

Inheritance is ………..in nature.

A. Intransitive

B. Transitive

C. Both A & B

D. None of the above

ANSWER: B

One Mark Question : Operator Overloading

Which of the following operators cannot be overloaded?

a. The -> operator

b. The . operator

c. The [ ] operator

d. The & operator


Ans. b

For operators to be overloaded as non static member function :

a. Both binary and unary operators take one argument

b. Binary operators can have one argument and unary operators cannot have any.

c. Neither binary nor unary operators can have arguments.

d. Binary operators can have two arguments and unary operators can have one.

Ans. b

For overloading += implicitly_____.

a. + and = operators need to be overloaded implicitly

b. Only + operator need to be overloaded implicitly

c. Only = operator need to be overloaded implicitly

d. The += operator cannot be overloaded implicitly

Ans. D

One can redefine the working of ____to work with objects.

a0 Preprocessor directives

b0 White space characteristics.

c0 Standard operators

d0 None of these

Ans. C

Choose the correct option.

I If you do not want to make use of operator overloading, you can achieve that effect using user
defined function.

II The sizeof operator can be overloaded.

a0 Only I is true

b0 Only II is true

c0 Both I and II are true

d0 Neither I nor II are true


Ans. A

Choose the correct choice.

a. The conditional operator can be overloaded.

b. While overloading using the friend function the binary operator requires one argument.

c. Operator precedence cannot be changed.

d. None of these.

Ans. c

Which of the following operator can be overloaded through friend function?

a. ()

b. []

c. ->

d. *

Ans. d

When we overload we want to ________.

a. Compare and copy object

b. Assign one object to another

c. compare two objects

d. Test for equality

Ans. B

One Mark on Inheritance

The inheritance mechanism provides the means of deriving______.

a. New operator from existing one

b. New function from existing one

c. New class from existing one

d. All of these

Ans. C
The inheritance is described as a ________relationship

a. has a

b. is a

c. association

d. None of these

Ans. b

Irrespective of the type of derivation_____members of base class are never accessible in derived
class

a. Public

b. Private

c. Protected

d. None of these

Ans. b

Which of the following allows you to create a derived class that inherits properties from more than
one base class?

a. Multilevel inheritance

b. Multiple inheritance

c. Single inheritance

d. Hybrid inheritance

Ans. b

The principle by which the knowledge of general category can be applied to more specific objects is
called_______.

a. Polymorphism

b. Overriding

c. Inheritance

d. None of these

Ans. a
Using multiple inheritance________.

a. There can be virtual class

b. It cannot include virtual class

c. The base classes must have only default constructor

d. None of these

Ans. a

If class C is a derived class of class B and class B is a derived class of A. If we istantiate class B object
then the first constructor called belongs to class ____.

a. A

b. B

c. Can be A or B

d. One cannot achieve such inheritance

Ans. A

Suppose class Derived is derived from a class Base privately. The object of class Derived is located in
main() can access _______.

a. Public members of Base

b. Private members of Base

c. Protected members of Base

d. Public members of Derived

Ans. d

What does the derived class does not inherit from the base class_____.

a. Constructor and destructor

b. Operator=() member

c. Friends

d. All of these

Ans. D

If class A is a friend class of class B, if class B is friend class of class C then ______.

a0 Class C is friend class of A


b0 Class A is friend class of class C

c0 Class A and C do not have any friendship relation.

d0 None of these

Ans.c

________class is tightly coupled with other class.

a. Friend

b. Virtual

c. Abstract

d. None of these

Ans. a

Q. 66 The keyword friend is used in _______

a. The class allowing access to anther class

b. The private section of a class

c. The public section of a class

d. All of these

Ans. d

One Mark on Virtual Function

When a class uses dynamic memory allocation, the destructor of the class must _____.

a.set all dynamically allocated data to zero

b.return any dynamically allocated memory to the system

c.explicitly destroy all the objects of the class

d.All of the above

Ans. c
Which of the following statements correctly allocates space to store 15 real numbers?

a.double *dptr = new double[15];

b.double dptr = new double[15];

c.double *dptr = new double[14];

d.real *iptr = new real[14];

Ans. a

Which of the following is not a legal value to initialize a pointer variable?

a.zero

b.null

c.0

d.The address of a variable of the same type

Ans. a

If a class uses dynamic memory allocation, which statement is true?

a.It must not use dynamic memory allocation in a copy constructor.

b.All the allocated memory must be deallocated before the object goes out of scope
and the destructor is called.

c.It must not overload the assignment operator.

d.It must include the dynamic allocation in all the constructors, and it must then
deallocate all of the allocated memory in the destructor.

Ans. d

Another definition for dynamic binding is _____.

a.late binding

b.early binding

c.dynamic allocation

d.It is not a defined term in C++ programming.

Ans. a
The new operator returns to_________.

a. returns pointer to new variable

b. creates a variable named 'new'

c. creates a memory for the variable.

d. tells the size of the memory allocated for the variable.

Ans. c

The operand for an operator delete is_______.

a.stack

b.array

c.pointer

d.none of these

Ans. c

Following is used to allocate and deallocate the memory for the object.

a.stack

b.garbage collection

c.heap

d.none of these

Ans. c

what is the size of heap memory?

a. 100 MB

b. 1000 MB

c. 1024 MB

d. Unlimited

Ans. d

When the new operator is used then constructor is __________.

a. default constructor
b. dynamic constructor

c. parameterized constructor

d. none of these

Ans. b

The binding of a function call at runtime is

a) Static binding

b) Early binding

c) Late binding

d) Runtime binding

Which of the following keyword supports dynamic method resolution?

A. abstract

B. Virtual

C. Dynamic

D. Typeid

Ans: B

One mark Question : Abstract base class and container

An abstract class is useful when _______.

a. no classes should be derived from it

b. there are multiple path from one derived class to another.

c. no objects can be instantiated from it.

d. none of these.

Ans. C
A pure virtual function is a function that_______

a. causes its class to be abstract.

b. returns nothing

c. takes no arguments

d. none of these

Ans a

choose the correct statement

a. an abstract base class can have pure virtual destructor.

b. an abstract base class can have virtual destructor

c. an abstract base class can have non virtual destructor

d. an abstract base class cannot have destructor.

Ans. D

What does the size of the vector refers to in c++?

a) Size of vector

b) Type of vector

c) Number of elements

d) None of the mentioned

ans. c

Two Mark Question : Operator Overloading

What will be the output of the following program?

#include<iostream>

Using namespace std;

Class TEST

Public:

Int x,y;

TEST() {};
TEST(int,int);

TEST operator + (TEST);

};

TEST::TEST(int a , int b)

X = a;

Y = b;

TEST TEST::operator + (TEST ob)

TEST temp;

Temp.x = x + ob.x;

Temp.y = y + ob.y;

Return(temp);

Int main()

TEST a (10,20);

TEST b (1,2);

TEST c;

C=a + b;

Cout << c.x<< “,” << c.y;

Return o;

a0 10 20

b0 1 2

c0 11 22

d0 30 3

Ans. c
What will be the output of the following code ?

# include <iostream>

Using namespace std;

Class A

Public:

A(int a)

Cout<<” “<<a;

};

Class B: public A

Public:

B(int a,int b):A(a)

Cout<<” “<<b;

};

Class C:public B

Public:

C(int a,int b,int c):B(a,b)

Cout<<” “c;

};

Int main()

C c(10,20,30);

Return 0;
}

a0 Garbage garbage 30

b0 30 20 10

c0 10 20 30

d0 Syntax error

Ans. C

What is the output of the following code ?

# include <iostream>

Using namespace std;

Class Base

Protected:

Int a;

Public:

Base(int x)

a= x;

~Base()

{ }

};

Class Derived: public Base

Int b;

Public:

Derived(int x, int y): Base(y)

b= x;

}
~Derived()

{ }

Void display()

Cout<<a<<” “<<b<<endl;

};

Int main()

Derived obj(100,200);

Obj.display();

Return 0;

a0 100 200

b0 200 100

c0 Syntax error

d0 100 100

Ans. b

What is the output of the following code?

# include <iostream>

Using namespace std;

Class Base

Public:

Base()

Cout <<”Tn Base class” <<endl;

};
Class derived: public Base

Public:

Derived()

Cout<<”In Derived class”<<endl;

};

Int main()

Cout<<”\tCreating Base class object…..”<<endl;

Base b;

Cout<<”\tCreating Derived class object…..”<<endl;

Derived d;

Return 0;

a0 Creating Base class object….

Creating Derived class object….

In Base class

In Derived class

b0 Creating Base class object….

In Base class

Creating Derived class object….

In Derived class

c0 Creating Derived class object….

In Base class

Creating Base class object….

In Base class

In Derived class

d0 Creating Base class object….

In Base class
Creating Derived class object….

In Base class

In Derived class

Ans. d

What is the output of the following code ?

# include <iostream>

Using namespace std;

Class Base

Public:

Base(void)

Cout <<” Base (void)\n” ;

Base (int i)

Cout < < “Base(“< <i < <”)\n”;

};

Base()

Cout<< Base() \n”;

};

};

Class D1 :public Base { };

Class D2 :public Base

Public:

D2(void)

Cout < < “D2()\n”;


}

D2 (int i) : Base (i)

Cout < <”D2(“ < < i< <”)\n”;

~D2(void)

Cout < < “~D2()\n”;

};

Int main(void)

D1 a;

D2 b;

D2 c(100);

Return 0;

a0 Base()

Base()

D2()

Base(100)

D2(100)

~D2()

~Base()

~D2()

~Base()

~Base()

b0 Syntax error

c0 Runtime error

d0 None of These

Ans. b
Class Test:public A, pubic B is an example of _______.

a. Single inheritance

b. Multiple inheritance

c. Repeated inheritance

d. None of these

Ans. b

Which of the following interface determines how your program will be used by other program?

a. Public

b. Private

C. Protected

d. None of these

Ans. a

What will be the output of the following code ?

# include <iostream>

Using namespace std;

Class A

Protected:

Int x,y;

Public:

Void setvalues(int a, int b)

X = a; y = b;

};

Class B

Public:
Void display (int i);

};

Void B::display(int i)

Cout < < i< <endl;

Class C: public A,public B

Public:

Int add()

Return(x + y);

};

Class D: public A, public B

Public:

Int add()

Return(x + y +10);

};

Int main()

C obj1;

D obj2;

Obj1.setvalues(10,20);

Obj2.setvalues(10,20);

Obj1.display(obj1.add());

Obj2.display(obj2.add());

Return 0;
}

a0 10 20

b0 30 40

c0 20 40

d0 None of these

Ans. b

What are the design requirements for building a container from the sratch?

a) Container interface requirements

b) Allocator interface requirements

c) Iterator requirements.

d) All of the mentioned

Ans. D

Which design patterns benefit from the multiple inheritance?

a) Adapter and observer pattern

b) Code pattern

c) Glue pattern

d) None of the mentioned

Ans. a

The new operator

A. returns a pointer to the variable

B. creates a variable called new

C. obtains memory for a new variable

D. tells how much memory is available

ANSWER: C
___ and __are used for dynamic memory allocation in C++.

A. Cin and cout

B. classes and objects

C. constructors and destructors

D. delete and new

ANSWER: D

What type of class member is operator new?

A. static

B. dynamic

C. const

D. smart

ANSWER: B

What must be an operand of operator delete?

A. Pointer

B. Array

C. Stack

D. None of the mentioned

ANSWER: A

If new operator is used, then the constructor function is

A. Parameterized constructor

B. Copy constructor

C. Dynamic constructor

D. Default constructor

ANSWER: C

In which case is it mandatory to provide a destructor in a class?

A. Almost in every class

B. Class for which two or more than two objects will be created
C. Class for which copy constructor is defined

D. Class whose objects will be created dynamically

ANSWER: D

What is the size of heap memory?

A. 100 MB

B. 1000 MB

C. 1024 MB

D. Unlimited

ANSWER: D

Which of the following is the proper keyword to deallocate memory?

A. free

B. delete

C. clear

D. remove

ANSWER: B

We should use the delete operator for objects that were___________

A. not correctly initialized

B. created with'new operator'

C. created by just declaration

D. none of these

ANSWER: B

When a class uses dynamic memory allocation, the destructor of the class must _____.

A. set all dynamically allocated data to zero

B. return any dynamically allocated memory to the system

C. explicitly destroy all the objects of the class

D. All of the above

ANSWER: C
Which of the following statements correctly allocates space to store 15 real numbers?

A. double *dptr = new double[15];

B. double dptr = new double[15];

C. double *dptr = new double[14];

D. real *iptr = new real[14];

ANSWER: A

Which of the following is not a legal value to initialize a pointer variable?

A. zero

B. null

C. 0

D. The address of a variable of the same type

ANSWER: A

If a class uses dynamic memory allocation, which statement is true?

A. It must not use dynamic memory allocation in a copy constructor.

B. All the allocated memory must be deallocated before the object goes out of scope and the
destructor is called.

C. It must not overload the assignment operator.

D. It must include the dynamic allocation in all the constructors, and it must then deallocate all of
the allocated memory in the destructor.

ANSWER: D

Which of the following is the proper keyword to allocate memory in C++?

A. new

B. malloc

C. create

D. value

ANSWER: A

Among following which will give the size of object or type?


A. calloc

B. malloc

C. sizeof

D. realloc

ANSWER: C

If new operator is used, then the consructor function is?

A. Copy constructor

B. Default constructor

C. Static constructor

D. Dynamic constructor

ANSWER: D

Which area of process address space is used for dynamic memory allocation?

A. Stack

B. Heap

C. Garbage Collection

D. Anywhere

ANSWER: B

Which of the following is correct to allocate a memory for an int array of size 5?

A. int * foo; foo= new int [5];

B. int * foo; foo= 5 new int;

C. int * foo; foo= [5] new int;

D. int * foo; foo= int [5] new ;

ANSWER: A

What is the purpose of operator delete?

A. To delete stored data

B. To delete complete process address space

C. Free the memory which is no longer needed


D. To change the stored value

ANSWER: C

Which of the following is correct to deallocate a memory for an int array of size 5?

A. delete [5] pointer;

B. delete pointer;

C. delete pointer [5];

D. delete;

ANSWER: A

Which of the following statements are illegal?

A. int *p= new int (15);

B. int *p= new int;

C. int *p=new int [10];

D. double *p= new dpuble;

ANSWER: A

Which operator allocates storage of the proper size for an object at execution time?

A. new

B. create

C. init

D. allocate

ANSWER: A

If a pointer of type double is declared (as shown below), which is the correct syntax to allocate
memory for 10 double variables?

double * ptr;

A. *ptr= new double[10]

B. ptr=new [10]

C. ptr=new double[10]

D. ptr=new [10] double


ANSWER: A

Allocation and freeing of memory can be done explicitelty using

A. Constructor and desructor

B. Class and objects

C. Inheritance and polymorphism

D. Function overloading

ANSWER: A

An abstract class is useful when

A. No class should be derived from it

B. There are multiple paths from one derived class to another

C. No objects can be instantiated from it

D. None of these

ANSWER: C

The private data members of a class are accessible ?

A. Directly to objects of that class

B. To any function defined outside a class

C. Only to the member functions

D. Only using keyword static

ANSWER: C

Code re usability increase if:

A. It has ADT's implemented

B. It is written in modules

C. It has semantic aspect

D. All of the above

ANSWER: D

Which of the following disadvantages are related to reusable software library?


A. Cost of acquiring, learning, and configuring the library

B. Inability to tweak details which may affect performance or the desired output

C. Problems associated with plagiarism and copyright issues

D. All of these

ANSWER: D

For a code to be reusable, it has to be which of the following?

A. Generalizable or generic

B. Easily extendibles

C. Both A and B

D. None of these

ANSWER: C

Which of the following is not an example of code re usability?

A. Functions or subroutines

B. Libraries like STL

C. Polymorphism

D. Algorithms

ANSWER: D

In a C++ class, which feature enables the user to pass different data types as arguments to the same
function?

A. polymorphism

B. encapsulation

C. member function

D. inheritance

ANSWER: A

When a class is implemented as an ADT, which of the following should normally be true ?

A. Member functions are private, member variables are public

B. Member functions are public, member variables are private


C. Member functions as well as member variables are private

D. Member functions as well as member variables are public

ANSWER: B

Which is an ADT in C++ standard library?

A. int

B. Queue

C. double

D. none of the above

ANSWER: B

A reference is not

A. an alias for another variable

B. a pointer

C. the name of a storage location

D. approximate self dereferencing constant pointer

ANSWER: B

Which member selector is used with a pointer to an object?

A. .

B. ->

C. ~

D. none of the above

ANSWER: B

A member of a class is accessed using the

A. Comma operator

B. The dot operator

C. The indexing operator

D. The ampersand operator

ANSWER: B
The major goal of inheritance in C++ is

A. To facilitate the conversion of data types

B. To help modular programming

C. To facilitate the reusability of code

D. To extend the capabilities of a class

ANSWER: C

Another definition for dynamic binding is _____.

A. late binding

B. early binding

C. dynamic allocation

D. It is not a defined term in C++ programming.

ANSWER: A

The binding of a function call at runtime is

A. Static binding

B. Early binding

C. Late binding

D. Runtime binding

ANSWER: C

Which of the following keyword supports dynamic method resolution?

A. abstract

B. Virtual

C. Dynamic

D. Typeid

ANSWER: B

Early binding is also known as:

A. Static binding
B. Runtime binding

C. dynamic binding

D. Easy binding

ANSWER: A

The concept of function pointers can be implemented through:

A. Early binding

B. Late binding

C. Both A & B

D. Neither A nor B

ANSWER: B

Which of the following sentences are true:

1. Late binding enables indirect function calls.

2. Early binding enables direct function calls.

A. Only 1

B. Only 2

C. 1 and 2

D. Neither 1 nor 2

ANSWER: C

Which of the following is not true about early binding?

A. It allows computer to directly associate the identifier's name

B. It jumps to the function's address directly

C. It takes two steps (de-refrencing and jumping to address)

D. It directly calls the function (Direct function call)

ANSWER: C

Late binding is also called as:

A. Dynamic polymorphism

B. Dynamic binding
C. Both A & B

D. Compile-time polymorphism

ANSWER: C

Polymorphism is implemented through which mechanism in C++ ?

A. Late Interpretation

B. Late Binding

C. Early Binding

D. Overloading

ANSWER: C

Which of the following concepts means determining at runtime what method to invoke?

A. Data hiding

B. Dynamic Typing

C. Dynamic binding

D. Dynamic loading

ANSWER: C

A program decides after it begins to run what function to execute in response to a statement such as
refToObject.func() is not an example of

A. polymorphism

B. late binding

C. early binding

D. virtual functions

ANSWER: C

Dynamic binding is also known as ___

A. Early binding

B. Static binding

C. Late binding

D. None
ANSWER: C

Which of the following refer to the different topic?

A. Early binding

B. Late binding

C. Virtual functions

D. Polymorphism

ANSWER: A

The advantage of declaring a virtual function as pure is?

A. programs runs faster

B. early binding can be achieved

C. you force any derived class to define its own implementation

D. you can avoid making the class an abstract class

ANSWER: B

In which of the following mechanisms, types of all variables and expressions are fixed at compilation
time.

A. Strong Typing

B. Weak Typing

C. Static Binding/ early binding

D. Dynamic Binding/ late binding

ANSWER: C

In which of the following mechanisms, types of all variables and expressions are decided at run time.

A. Strong Typing

B. Weak Typing

C. Static Binding/ early binding

D. Dynamic Binding/ late binding

ANSWER: D
Direct function calls can be resolved through a process known as?

A. Early Binding

B. Dynamic Binding

C. Both A and B

D. Overloading

ANSWER: A

Binding is an association of objects with

A. Identifiers

B. Classes

C. Pointers

D. Friend Class

ANSWER: A

The runtime system performs ------------- on virtual functions

A. Additional error checking

B. Dynamic Binding

C. Static Binding

D. No special srvices

ANSWER: B

In which of the following mechanisms, types of all variables and expressions are not known until
runtime

A. Strong Typing

B. Weak Typing

C. Static Binding/ early binding

D. Dynamic Binding/ late binding

ANSWER: D

Dynamic binding is necessary when we refer to derived class object with -----

A. Global pointer
B. Base class pointer

C. Derived class pointer

D. Non pointer variable

ANSWER: B

In which binding it is not possible to know which function will be called until runtime

A. Early Binding

B. Late Binding

C. Both A and B

D. None of the above

ANSWER: B

Which of the following is not correct

A. late binding is more flexible than early binding

B. Late binding is slightly less efficient than early binding

C. Early binding is more flexible than late binding

D. All of the above

ANSWER: C

Indirect function calls can be resolved through a process known as?

A. Early Binding

B. Dynamic Binding

C. Both A and B

D. Overloading

ANSWER: B

Calling a function via a function pointer is also known as

A. Inheritance

B. Overloading

C. Direct Function Call

D. Indirect Function Call


ANSWER: D

Array of objects of classes are initialized by default with?

A. function variables

B. at class constructor

C. at friend function

D. with global in main()

ANSWER: B

Array of objects of user defined data type can be done using

A. Class

B. Structure

C. Enum

D. All of these

ANSWER: D

Data members and member functions are enclosed within?

A. union

B. structure

C. class

D. array

ANSWER: C

What is the purpose of abstract class?

A. to provide help with database connectivity.

B. to provide data input to other classes.

C. to provide security to other classes.

D. to provide an appropriate base class from which other classes can inherit.

ANSWER: D

How to delete a pointer?


A. Using delete commanD.

B. Assigning null

C. Assigning it null and then deleting the pointer

D. None of these

ANSWER: C

Which of the following statements is correct?

A. Base class pointer cannot point to derived class

B. Derived class pointer cannot point to base class

C. Pointer to derived class cannot be created

D. Pointer to base class cannot be created

ANSWER: B

A pointer to the base class can hold address of

A. only base class object

B. only derived class object

C. base class object as well as derived class object

D. None of the above

ANSWER: C

A function that is expanded in line when it is invoked

A. normal function

B. operator overloading

C. explicit function

D. inline functions

ANSWER: D

Inline function is similar to ___________ in C

A. recurcive function

B. macros

C. call by value
D. structure

ANSWER: B

Inline function cannot be expanded in situation like

A. if inline functions are recursive

B. inline function contains static variable

C. both a and b

D. neither a nor b

ANSWER: C

Inline keyword sends a

A. request to compiler

B. command to compiler

C. runtime error

D. none of the above

ANSWER: A

Inline expansion makes a program run fast because

A. it is normal function

B. the overhead of a function call and return is eliminated.

C. it has static variables

D. none of the above

ANSWER: B

Static member variables must be defined

A. inside the class defination

B. outside the class defination

C. inside any function of the class

D. both a and c

ANSWER: B
A static funct___________ members of the base class are never accessible by the deried class.

A. private

B. public

C. protected

D. all of these

ANSWER: A

Static variables are associated with class rather than with any class object so they are known as

A. local variable

B. global variable

C. class variable

D. either a or b

ANSWER: C

The special character used to mark the end of class is

A. :

B. ;

C. #

D. none of these

ANSWER: B

Class cannot be

A. virtual

B. inline

C. generic

D. friend

ANSWER: B

The direct member access operator is

A. Scope resolution

B. # operator
C. dot operator

D. none of these

ANSWER: C

If keyword struct is used instead of class then the access of the members will be

A. public by default

B. private by default

C. protected by default

D. none of these

ANSWER: A

The class having another class definition is called

A. nested class

B. derived class

C. subordinate class

D. none of these

ANSWER: C

Which of the following is an abstract type

A. int

B. double

C. char

D. class

ANSWER: D

In a class, member variables are often called as its______________ and member functions are called
its _______________

A. values,activities

B. data,actions

C. attributes,rules

D. attributes,methods
ANSWER: D

Following construct is similar to class

A. struct

B. union

C. both a and b

D. object

ANSWER: C

Choose the correct statement from the given below

A. Data items in class must be private

B. Member functions in class must be public

C. both data and fuction can be either public or private

D. none of these

ANSWER: C

The inheritance mechanism provides the means of deriving

A. new operator from existing one

B. new function from existing one

C. new class from existing one

D. all of these

ANSWER: C

The derived class is derived from

A. derived class

B. base class

C. both a and b

D. none of these

ANSWER: B

Which of the following can be inherited by the derived class


A. Data members

B. Member functions

C. both a and b

D. none of these

ANSWER: C

Which of the following allows you to create a derived class that inherits properties from more than
one base class

A. Multilevel inheritance

B. Multiple inheritance

C. Single inheritance

D. Hybrid inheritance

ANSWER: B

Parent:child is

A. base:derived

B. derived:driven

C. chid:super

D. subclass:superclass

ANSWER: A

What is the syntax of inheritance of a class

A. Class class_name

B. Class name:access specifier

C. Class name:access specifier class name

D. None of these

ANSWER: C

If an attribute is private then which method have access to it

A. Only static methods in the same class

B. only the methods defined in that class


C. only the methods of same package

D. none of these.

ANSWER: B

Which symbol is used to create multiple inheritance

A. dot

B. comma

C. hash #

D. dollar

ANSWER: B

In public inheritance

A. code reusability

B. virtual function overloading

C. subtyping

D. all of the above

ANSWER: D

If class A inherits from class B then B is called_____________ and A is called __________of B

A. superclass and subclass

B. subclass and superclass

C. subclass and childclass

D. superclass and parentclass

ANSWER: A

Which of the following statements are correct

I) Class is a way to bind data and associated functions together

II) Class is treated like a datatype.

A. Only 1

B. Only 2

C. Both
D. None

ANSWER: C

The keywords private and public are called as

A. Access specifiers

B. Format specifiers

C. Visibility labels

D. Both A&C

ANSWER: D

Private data members and private functions in a class can be accessed

A. In main using object of class

B. By member functions

C. Both

D. None

ANSWER: B

Which of the following statements are correct I) Private member functions can be called by another
member function II) An object can access the private variables using dot operator in main

A. Only I

B. Only II

C. Both

D. None

ANSWER: A

A static member

A. Is initialized to zero when the first object is created

B. Has Only one copy of it created for the entire class

C. Visible only within the class but lifetime is the entire program

D. All of these

ANSWER: D
Which of the following is correct?

A static member function

A. Can have access to only static members declared in the same class

B. Can have access to static members declared in all the classes

C. can have access to all the members of the same class

D. can have access to all the public members in all the classes

ANSWER: A

A friend function

A. Is in the scope of the class of which it is declared as a friend

B. Should be called using the object of the class of which it is a friend

C. Can access the member names using an object name and a dot membership operator

D. Should be declared in the public section of the class only

ANSWER: C

Classes can be defined and used inside a function which are known as

A. Inbuilt classes

B. Inline classes

C. Local classes

D. Enclosed classes

ANSWER: C

A constructor that accepts no parameters is called a

A. Non parametrized constructor

B. Default constructor

C. Copy constructor

D. Void constructor

ANSWER: B
Which of the following statements are wrong

A. Constructors should be called in the public section

B. They are invoked automatically when objects are created

C. They have return type void

D. They cannot be inherited

ANSWER: C

A _______ constructor takes a reference to an object of the same class as itself as an argument

A. Reference constructor

B. Copy constructor

C. Self constructor

D. None of these

ANSWER: B

A copy constructor is called when

A. When object is passed by value

B. When function returns object

C. When object is defined and initialized with another object

D. All of these

ANSWER: D

State true or false I. A destructor never takes any argument nor does it return any value II. It releases
memory space for further use

A. True,true

B. True, false

C. False,true

D. False,false

ANSWER: A

Automatic initialization of the of object is carried out using a special member function called

A. Friend
B. Casting

C. Reference parameter

D. Constructor

ANSWER: D

If a constructor is defined in the private section then

A. Any number of objects can be created

B. Objects cannot be created

C. Only one unique object can be created

D. None of these

ANSWER: B

If a class does not have a name

A. The constructor cannot be created

B. Destructor cannot be created

C. Generate syntax error

D. Both a&b

ANSWER: D

To eliminate cost of calls to small functions c++ proposes a new feature

A. Static functions

B. Virtual functions

C. Inline functions

D. None

ANSWER: C

Inline expansion does not work

A. For functions containing static variables

B. If inline functions are non recursive

C. Both

D. None
ANSWER: A

Member functions declared inside the class are

A. Always inline

B. Not line

C. Private

D. Inline if they are not too big

ANSWER: A

________ pointer cannot be modified

A. That pointer

B. This pointer

C. Address pointer

D. None

ANSWER: B

Constructors are executed when

A. Objects are initialized

B. Objects are created

C. Class is declared

D. None of these

ANSWER: B

Consider the following derivation Class ABC: XYZ { Members of ABC };

A. XYZ is inherited publicly

B. XYZ is inherited privately

C. XYZ is not inherited as access specifier not specified

D. None of these

ANSWER: B
In which of the ways can a class be privately inherited <br>1. Class A:private B <br>2. Class
A:protected B <br>3. Class A: B <br>4. Class <br> A:public B

A. 1

B. 1,2,3

C. 1,3

D. 1,2,3,4

ANSWER:C

Where does keyword ‘friend’ should be placed?

A. function declaration

B. function definition

C. main function

D. None of the mentioned

ANSWER: A

What is the syntax of friend function?

A. friend class1 class2;

B. friend class;

C. friend class

D. None of the above

ANSWER: A

Pick out the correct statement.

A. A friend function may be a member of another class.

B. A friend function may not be a member of another class.

C. A friend function may or may not be a member of another class.

D. None of the mentioned

ANSWER: C

What are the things are inherited from the base class?

A. Constructor and its destructor


B. Operator=() members

C. Friends

D. All of the mentioned

ANSWER: D

What is a function template?

A. creating a function without having to specify the exact type.

B. creating a function with having a exact type.

C. both a & b

D. none of the mentioned

Answer:a

Which is used to describe the function using placeholder types?

A. template parameters

B. template type parameters

C. template type

D. none of the mentioned

Answer:b

Explanation:During runtime, We can choose the appropriate type for the function

and it is called as template type parameters.

Pick out the correct statement.

A. you only need to write one function, and it will work with many different

types.

B. it will take a long time to execute

C. duplicate code is increased

D. none of the mentioned

Answer:a
Explanation:Because of template type parameters, It will work with many types and saves a lot of

time.

What is the output of this program?

#include <iostream>

using namespace std;

template

type Max(type Var1, type Var2)

return Var1 > Var2 ? Var1:Var2;

int main()

int p;

p = Max(100, 200);

cout << p << endl;

return 0;

A. 100

B. 200

C. 300

D. 100 200

Answer:b

Explanation:In this program, We are returning the maximum value by using function template.

Output:

$ g++ ftemp.cpp

$ a.out

200

What is the output of this program?


#include <iostream>

using namespace std;

template

class Test

public:

Test()

};

~Test()

};

type Funct1(type Var1)

return Var1;

type Funct2(type Var2)

return Var2;

};

int main()

Test Var1;

Test Var2;

cout << Var1.Funct1(200) << endl;

cout << Var2.Funct2(3.123) << endl;

return 0;

A. 200 3.123

B. 3.123 200
C. 200

D. 3.123

Answer:a

Explanation:In this program, We are passing the values and getting it back from template. And we
are

using the constructor and destructor for the function template.

Output:

$ g++ ftemp1.cpp

$ a.out

200

3.123

What is the output of this program?

#include <iostream>

using namespace std;

template

class TestVirt

public:

virtual type TestFunct(type Var1)

return Var1 * 2;

};

int main()

TestVirt Var1;

cout << Var1.TestFunct(100) << endl;

return 0;

}
A. 100

B. 200

C. 50

D. none of the mentioned

Answer:b

Explanation:In this program, We are using class to pass the value and then we are manipulating it.

Output:

$ g++ ftemp3.cpp

$ a.out

200

What is the output of this program?

#include <iostream>

using namespace std;

template

inline T square(T x)

T result;

result = x * x;

return result;

};

int main()

int i, ii;

float x, xx;

double y, yy;

i = 2;

x = 2.2;

y = 2.2;

ii = square(i);
cout << i << "" << ii << endl;

yy = square(y);

cout << y << "" << yy << endl;

A. 2 4 2.2 4.84

B. 2 4

C. error

D. runtime error

Answer:a

Explanation:In this program, We are passing the values and calculating the square of the value by

using the function template.

Output:

$ g++ ftemp4.cpp

$ a.out

24

2.2 4.84

What is the output of this program?

#include <iostream>

using namespace std;

template

void loopIt(T x)

T val[count];

for (int ii=0; ii < count; ii++)

val[ii] = x++;

cout << val[ii] << endl;

};
int main()

float xx = 2.1;

loopIt(xx);

A. 2.1

B. 3.1

C. 3.2

D. 2.1 3.1 4.1

Answer:d

Explanation:In this program, We are using the for loop to increment the value by 1 in the function

template.

Output:

$ g++ ftemp5.cpp

$ a.out

2.1

3.1

4.1

What can be passed by non-type template parameters during compile time?

A. int

B. float

C. constant expression

D. none of the mentioned

Answer:c

Explanation:Non-type template parameters provide the ability to pass a constant expression at

compile time. The constant expression may also be an address of a function, object or static class

member.
From where does the template class derived?

A. regular non-templated C++ class

B. templated class

C. a or b

D. none of the mentioned

Answer:c

What is meant by template parameter?

A. It can be used to pass a type as argument

B. It can be used to evaluate a type.

C. It can of no return type

D. None of the mentioned

Which keyword can be used in template?

A. class

B. typename

C. both a & b

D. function

What is the validity of template parameters?

A. inside that block only

B. inside the class

C. whole program

D. any of the mentioned

What is the output of this program?

#include <iostream>

using namespace std;


template <class T, int N>

class mysequence

T memblock [N];

public:

void setmember (int x, T value);

T getmember (int x);

};

template <class T, int N>

void mysequence<T,N> :: setmember (int x, T value)

memblock[x] = value;

template <class T, int N>

T mysequence<T,N> :: getmember (int x)

return memblock[x];

int main ()

mysequence <int, 5> myints;

mysequence <double, 5> myfloats;

myints.setmember (0, 100);

myfloats.setmember (3, 3.1416);

cout << myints.getmember(0) << '\n';

cout << myfloats.getmember(3) << '\n';

return 0;

A. 100

B. 3.1416

C. 100 3.1416
D. none of the mentioned

Answer:c

Explanation:In this program, We are printing the integer in the first function and float in the second

function.

Output:

$ g++ farg.cpp

$ a.out

100 3.1416

What is the output of this program?

#include <iostream>

using namespace std;

template <class T>

T max (T a, T b)

return (a>b?a:b);

int main ()

int i = 5, j = 6, k;

long l = 10, m = 5, n;

k = max(i, j);

n = max(l, m);

cout << k << endl;

cout << n << endl;

return 0;

A. 6

B. 6 10

C. 5 10
D. 6 5

Answer:b

Explanation:In this program, We are using the ternary operator on the template function.

Output:

$ g++ farg.cpp

$ a.out

6 10

What is the output of this program?

#include <iostream>

using namespace std;

template <class type>

class Test

public:

Test()

};

~Test()

};

type Funct1(type Var1)

return Var1;

type Funct2(type Var2)

return Var2;

};
int main()

Test<int> Var1;

Test<double> Var2;

cout << Var1.Funct1(200);

cout << Var2.Funct2(3.123);

return 0;

A. 100

B. 200

C. 3.123

D. 200 3.123

Answer:d

Explanation:In this program, We are passing the value and returning it from template.

Output:

$ g++ farg3.cpp

$ a.out

200 3.123

What is the output of this program?

#include <iostream>

using namespace std;

template <typename T, int count>

void loopIt(T x)

T val[count];

for(int ii = 0; ii < count; ii++)

val[ii] = x++;

cout << val[ii] << endl;


}

};

int main()

float xx = 2.1;

loopIt<float, 3>(xx);

A. 2.1

B. 3.1

C. 4.1

D. 2.1 3.1 4.1

Answer:d

Explanation:In this program, We are using the non-type template parameter to increment the value
in

the function template.

Output:

$ g++ farg4.cpp

$ a.out

2.1

3.1

4.1

Why we use :: template-template parameter?

A. binding

B. rebinding

C. both a & b

D. none of these

Answer:c

Explanation:It is used to adapt a policy into binary ones.


Which parameter is legal for non-type template?

A. pointer to member

B. object

C. class

D. none of the mentioned

Answer:a

Explanation:The following are legal for non-type template parameters:integral or enumeration type,

Pointer to object or pointer to function, Reference to object or reference to function, Pointer to

member.

Which of the things does not require instantiation?

A. functions

B. non virtual member function

C. member class

D. all of the mentioned

Answer:d

Explanation:The compiler does not generate definitions for functions, non virtual member functions,

class or member class because it does not require instantiation.

What is meant by template parameter?

A. It can be used to pass a type as argument

B. It can be used to evaluate a type.

C. It can of no return type

D. None of the mentioned

Answer:a

Explanation:A template parameter is a special kind of parameter that

can be used to pass a type as argument.


Which keyword can be used in template?

A. class

B. typename

C. both a & b

D. function

Answer:c

What is the validity of template parameters?

A. inside that block only

B. inside the class

C. whole program

D. any of the mentioned

Answer:a

What is the output of this program?

#include <iostream>

using namespace std;

template <class T, int N>

class mysequence

T memblock [N];

public:

void setmember (int x, T value);

T getmember (int x);

};

template <class T, int N>

void mysequence<T,N> :: setmember (int x, T value)

memblock[x] = value;
}

template <class T, int N>

T mysequence<T,N> :: getmember (int x)

return memblock[x];

int main ()

mysequence <int, 5> myints;

mysequence <double, 5> myfloats;

myints.setmember (0, 100);

myfloats.setmember (3, 3.1416);

cout << myints.getmember(0) << '\n';

cout << myfloats.getmember(3) << '\n';

return 0;

A. 100

B. 3.1416

C. 100 3.1416

D. none of the mentioned

Answer:c

Explanation:In this program, We are printing the integer in the first function and float in the second

function.

Output:

$ g++ farg.cpp

$ a.out

100

3.1416

What is the output of this program?


#include <iostream>

using namespace std;

template <class T>

T max (T a, T b)

return (a>b?a:b);

int main ()

int i = 5, j = 6, k;

long l = 10, m = 5, n;

k = max(i, j);

n = max(l, m);

cout << k << endl;

cout << n << endl;

return 0;

A. 6

B. 6 10

C. 5 10

D. 6 5

Answer:b

Explanation:In this program, We are using the ternary operator on the template function.

Output:

$ g++ farg.cpp

$ a.out

10

What is the output of this program?


#include <iostream>

using namespace std;

template <class type>

class Test

public:

Test()

};

~Test()

};

type Funct1(type Var1)

return Var1;

type Funct2(type Var2)

return Var2;

};

int main()

Test<int> Var1;

Test<double> Var2;

cout << Var1.Funct1(200);

cout << Var2.Funct2(3.123);

return 0;

A. 100

B. 200
C. 3.123

D. 200 3.123

Answer:d

Explanation:In this program, We are passing the value and returning it from template.

Output:

$ g++ farg3.cpp

$ a.out

2003.123

What is the output of this program?

#include <iostream>

using namespace std;

template <typename T, int count>

void loopIt(T x)

T val[count];

for(int ii = 0; ii < count; ii++)

val[ii] = x++;

cout << val[ii] << endl;

};

int main()

float xx = 2.1;

loopIt<float, 3>(xx);

A. 2.1

B. 3.1

C. 4.1
D. 2.1

Answer:d

Explanation:In this program, We are using the non-type template parameter to increment the value
in the

function template.

Output:

$ g++ farg4.cpp

$ a.out

2.1

3.1

4.1

Why we use :: template-template parameter?

A. binding

B. rebinding

C. both a & b

D. none of these

Answer:c

Explanation:It is used to adapt a policy into binary ones.

Which parameter is legal for non-type template?

A. pointer to member

B. object

C. class

D. none of the mentioned

Answer:d

Explanation:The compiler does not generate definitions for functions, non virtual member functions,
class

or member class because it does not require instantiation.


What is a function template?

A. creating a function without having to specify the exact type.

B. creating a function with having a exact type.

C. both a & b

D. none of the mentioned

Answer:a

Which is used to describe the function using placeholder types?

A. template parameters

B. template type parameters

C. template type

D. none of the mentioned

Answer:b

Explanation:During runtime, We can choose the appropriate type for the function

and it is called as template type parameters.

Pick out the correct statement.

A. you only need to write one function, and it will work with many different

types.

B. it will take a long time to execute

C. duplicate code is increased

D. none of the mentioned

What is the output of this program?

#include <iostream>

using namespace std;

template
type Max(type Var1, type Var2)

return Var1 > Var2 ? Var1:Var2;

int main()

int p;

p = Max(100, 200);

cout << p << endl;

return 0;

A. 100

B. 200

C. 300

D. 100

Answer:b

Explanation:In this program, We are returning the maximum value by using function template.

Output:

$ g++ ftemp.cpp

$ a.out

200

You might also like