0% found this document useful (0 votes)
142 views4,280 pages

C++ Data Types and Functions Quiz

The document contains a quiz on C++ concepts with 60 multiple choice questions and answers. Some key points covered include: - The size of wchar_t in C++ depends on the number of bits in the system. - The void datatype is used to represent the absence of parameters in a function. - Escape codes in C++ represent special characters like tabs or backslashes. - When a language can define new datatypes, it is considered extensible. The quiz covers a wide range of fundamental C++ concepts like data types, operators, functions, loops, streams and more. It provides an overview of essential C++ knowledge that would be useful for someone learning the language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views4,280 pages

C++ Data Types and Functions Quiz

The document contains a quiz on C++ concepts with 60 multiple choice questions and answers. Some key points covered include: - The size of wchar_t in C++ depends on the number of bits in the system. - The void datatype is used to represent the absence of parameters in a function. - Escape codes in C++ represent special characters like tabs or backslashes. - When a language can define new datatypes, it is considered extensible. The quiz covers a wide range of fundamental C++ concepts like data types, operators, functions, loops, streams and more. It provides an overview of essential C++ knowledge that would be useful for someone learning the language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4280

UNIT-1

1.What is the size of wchar_t in C++?

A. 2

B. 4

C. 2 or 4

D. based on the number of bits in the system

ANSWER: A

2.Pick the odd one out

A. array type

B. character type

C. boolean type

D. integer type

ANSWER: A

3.Which datatype is used to represent the absence of parameters?

A. int

B. short

C. void

D. float

ANSWER: C

4.What does a escape code represent?

A. alert

B. backslash

C. tab

D. form feed

ANSWER: B

5.Which type is best suited to represent the logical values?

A. integer
B. boolean

C. character

D. all of the mentioned

ANSWER: B

6.Identify the user-defined types from the following?

A. enumeration

B. classes

C. both a and b

D. int

ANSWER: C

7.Which of the following statements are true? int f(float)

A. f is a function taking an argument of type int and retruning a floating point number

B. f is a function taking an argument of type float and returning a integer.

C. f is a function of type float

D. none of the mentioned

ANSWER: B

8.The value 132.54 can represented using which data type?

A. double

B. void

C. int

D. bool

ANSWER: A

9.When a language has the capability to produce new data type mean, it can be called as

A. overloaded

B. extensible

C. encapsulated

D. reprehensible
ANSWER: B

10.Pick the odd one out.

A. integer, character, boolean, floating

B. enumeration, classes

C. integer, enum, void

D. arrays, pointer, classes

ANSWER: C

11.<< is called

A. Insertion operator

B. Extraction operator

C. Object

D. Function

ANSWER: A

12.>> is called

A. Insertion operator

B. Extraction operator

C. Object

D. Function

ANSWER: B

13.cin object in c++ corresponds to the

A. standard input stream

B. standard output stream

C. Iterative statement

D. Function
ANSWER: A

14.The for loop is best if we know

A. Fixed number of iterations

B. Test condition

C. Value for calculation

D. Number of conditions are fixed

ANSWER: A

15.In while loop condition is evaluated

A. First then body is executed

B. After the execution of body

C. In between the body of the loop

D. After update statement is executed

ANSWER: A

16.In do__while loop the condition is evaluated

A. First then body is executed

B. After the execution of body

C. In between the body of the loop

D. After update statement is executed

ANSWER: B

17.To display output; what is used in C++

A. cout

B. cin

C. header file

D. class
ANSWER: A

18. Function prototype is also called

A. Function declaration

B. Function definition

C. Function call

D. Return type

ANSWER: A

19.Inline function should be used

A. Small set of code

B. Large set of code

C. Friend function

D. For main() function

ANSWER: A

20.Static variable should be defined

A. Inside the function

B. Outside the function

C. In the function call

D. Anywhere

ANSWER: B

21.Parameters associated with function call are called

A. Actual parameter

B. Formal parameter

C. Global parameter

D. Auto parameter
ANSWER: A

22.Parameters defined within the function are

A. Extern parameter

B. Formal parameter

C. Auto parameter

D. Register parameter

ANSWER: B

23.Which storage specifiers retains the value between the function call

A. Auto

B. Register

C. Extern

D. Static

ANSWER: D

24.If function does not return any value then its return type is

A. Int

B. Float

C. Void

D. Char

ANSWER: C

25.Maximum number of values that can be returned by any function

A. 1

B. 2

C. 0

D. 4
ANSWER: A

26.Lifetime of extern variable is

A. Function

B. File

C. Block

C. None

ANSWER: B

27.Which method of parameter passing does not change the original variable

A. Call by value

B. Call by reference

C. Call by pointers

D. Both b and c

ANSWER: A

28.C++ was originally developed by;

A. Clocksin and Mellish

B. Donald E. Knuth

C. Sir Richard Hadlee

D. Bjame Stroustrup

ANSWER: D

29.cfront

A. is the front end of a C compiler

B. is the pre-processor of a C compiler

C. is a tool that translates a C++ code to its equivalent C code

D. none of the above


ANSWER: C

30.Which of the followinig are procedural languages?

A. Pascal

B. Smalltalk

C. C

D. Both(a) and (c)

ANSWER: C

31.Choose the correct remarks.

A. C++ allows any operator to be overloaded.

B. Some of the existing operators cannot be overloaded.

C. Operator precedence cannot be changed.

D. All of the above.

ANSWER: C

32. Which of the following operators cannot be overloaded ?

A. >>

B. ?:

C. .

D. Both (b) and (c)

ANSWER: D

33.C++ encourages structuring .a software as a collection of components that are

A. highly cohesive and loosely coupled

B. not highly cohesive but loosely coupled

C. highly cohesive and tightly coupled

D. not highly cohesive but tightly coupled


ANSWER: A

34.cout stands for

A. class output

B. character output

C. common output

D. call output

ANSWER: C

35.What is the only function all C++ programs must contain?

A. start()

B. system()

C. main()

D. program()

ANSWER: C

36.What punctuation is used to signal the beginning and end of code blocks?

A. { }

B. -> and <-

C. BEGIN and END

D. ( and )

ANSWER: A

37.What punctuation ends most lines of C++ code?

A. . (dot)

B. ; (semi-colon)

C. : (colon)

D. ' (single quote)


ANSWER: B

38.Which of the following is a correct comment?

A. */ Comments */

B. ** Comment **

C. /* Comment */

D. { Comment }

ANSWER: C

39.Which of the following is not a correct variable type?

A. float

B. real

C. int

D. double

ANSWER: B

40.Which of the following is the correct operator to compare two variables?

A. :=

B. =

C. equal

D. ==

ANSWER: D

41.Which of the following is true?

A. 1

B. 66

C. .1

D. All of the above


ANSWER: D

42.Which of the following is the boolean operator for logical-and?

A. &

B. &&

C. |

D. |&

ANSWER: B

43.The void specifier is used if a function does not have return type.

A. True

B. False

C. --

D. --

ANSWER: A

44.The directives for the preprocessors begin with

A. Ampersand symbol (&)

B. Two Slashes (//)

C. Number Sign (#)

D. Less than symbol (<)

ANSWER: C

45.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. Both of these

D. None of these
ANSWER: A

46.There is a unique function in C++ program by where all C++ programs start their execution

A. Start()

B. Begin()

C. Main()

D. Output()

ANSWER: C

47.very function in C++ are followed by

A. Parameters

B. Parenthesis

C. Curly braces

D. None of these

ANSWER: B

48.Which of the following is false?

A. Cout represents the standard output stream in c++.

B. Cout is declared in the iostream standard file

C. Cout is declared within the std namespace

D. None of above

ANSWER: D

49.Every statement in C++ program should end with

A. A full stop (.)

B. A Comma (,)

C. A Semicolon (;)

D. A colon (:)
ANSWER: C

50.Which of the following statement is true about preprocessor directives?

A. These are lines read and processed by the preprocessor

B. They do not produce any code by themselves

C. These must be written on their own line

D. They end with a semicolon

ANSWER: D

51.A block comment can be written by

A. Starting every line with double slashes (//)

B. Starting with /* and ending with */

C. Starting with //* and ending with *//

D. Starting with <!- and ending with -!>

ANSWER: B

52.When writing comments you can

A. Use code and /* comment on the same line

B. Use code and // comments on the same line

C. Use code and //* comments on the same line

D. Use code and <!- comments on the same line

ANSWER: B

53.What is encapsulation?

A. It is collection of similar data items

B. It is combination of similar data items and the function

C. It is the combination of data items and function

D. It is the division of program into independent module


ANSWER: B

54.A variable is/are

A. String that varies during program execution

B. A portion of memory to store a determined value

C. Those numbers that are frequently required in programs

D. None of these

ANSWER: B

55.Which of the following can not be used as identifiers?

A. Letters

B. Digits

C. Underscores

D. Spaces

ANSWER: D

56.Which of the following identifiers is invalid?

A. papername

B. writername

C. typename

D. printname

ANSWER: C

57.Which of the following identifiers is invalid?

A. papername

B. writername

C. typename

D. printname
ANSWER: A

58.To increase the value of c by one which of the following statement is wrong?

A. c++;

B. c = c + 1;

C. c + 1 => c;

D. c += 1

ANSWER: C

59.The result of a Relational operation is always

A. either True or False

B. is less than or is more than

C. is equal or less or more

D. All of these

ANSWER: A

60.What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?

A. 10

B. 9

C. 0

D. 1

ANSWER: A

2 Marks marked rest quetions are of 1 marks

Q1. What is the size of wchar_t in C++?


a) 2
b) 4
c) 2 or 4
d) based on the number of bits in the system

Answer:d
Q2.which datatype is used to represent the absence of paramaters?
a) int
b) short
c) void
d) float

Answer:c

Q3.What does a escape code represent?


a) alert
b) backslash
c) tab
d) form feed

Answer:a

Q4.When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible

Answer:b

Q5.In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned

Answer:b

Q6.To which of these enumerators can be assigned?


a) integer
b) negative
c) enumerator
d) all of the mentioned

Answer:d

Q7. What will happen when defining the enumerated type?


a) it will not allocate memory
b) it will allocate memory
c) it will not allocate memory to its variables
d) none of the mentioned

Answer:a

Q8. Which variable does equals in size with enum variable?


a) int variable
b) float variable
c) string variable
d) none of the mentioned

Answer:a
Q9.Which allows you to create a derived class that inherits properties from more than one base class?
a. Multilevel inheritance
b. Multiple inheritance
c. Hybrid Inheritance
d. Hierarchical Inheritance

Answer:b

Q10. Which feature in OOP allows reusing code?


a. Polymorphism
b. Inheritance
c. Encapsulation
d. Data hiding

Answer:b

Q11. A function that changes the state of the cout object is called a(n) _____
a. member
b. adjuster
c. manipulator
d. operator
Answer:c

Q12. What does C++ append to the end of a string literal constant?
a. a space
b. a number sign (#)
c. an asterisk (*)
d. a null character

Answer:d

Q13. An array element is accessed using


a. a first-in-first-out approach
b. the dot operator
c. a member name
d. an index number

Answer:d

Q14. To hide a data member from the program, you must declare the data member in the _____ section of the class
a. concealed
b. confidential
c. restricted
d. private

Answer:d

Q15.The arguments that determine the state of the cout object are called
a. classes
b. manipulators
c. format flags or state flags
d. state controllers

Answer:c

Q16.Which of the following statements declares a variable that can contain a decimal number?
a. dec payRate;
b. dec hourlyPay
c. float payRate
d. float hourlyPay;

Answer:d

Q17. The statement int num[2][3]={ {1,2}, {3,4}, {5, 6} };


a. assigns a value 2 to num[1][2]
b. assigns a value 4 to num[1][2]
c. gives an error message
d. assigns a value 3 to num[1][2]

Answer:c

Q18.The standard input stream, which refers to the keyboard, is called


a. cin
b. cout
c. stin
d. stout

Answer:a

Q19. Elements in an array are identified by a unique _____


a. data type
b. order
c. subscript
d. symbol

Answer:c

Q20. The statement fwrite ( (char*)&objl, sizeof(objl) );


a. writes the member functions of objl to fl
b. writes the data in objl to fl
c. writes the member functions and me data of obj 1 to fl
d. writes the address of objl to fl

Answer:b

Q21. The body of a C++ function is surrounded by _____


a. parentheses
b. angle brackets
c. curly brackets
d. square brackets

Answer:c

Q22. Which of the following type casts will convert an Integer variable named amount to a Double type?
a. (double) amount
b. (int to double) amount
c. int to double(amount)
d. int (amount) to double

Answer:a

Q23.Which of the following, if any, are valid names for variables?


a. class
b friend
c. void
d. None of the above is valid names for variables

Answer:d

Q24. You have assigned the address of Value to the pointer P, Which statement will display the value stored in
Value?

a. cout<<P;
b. cout<<*Value;
c. cout<<&P;
d. cout<<*<P;

Answer:d

Q25. Type specifier is optional when declaring a function


a. True
b. False

Answer:b

Q26. A pointer to a block of memory is effectively same as an array


a. True
b. False

Answer:a

Q27. Does this mentioning array name gives the base address in all the contexts?
a. Yes
b. No

Answer:b

Q28. Is there any difference int the following declarations?


int fun(int arr[]);
int fun(int arr[2]);
a. Yes
b. No

Answer:b

Q29. Are the expressions arr and &arr same for an array of 10 integers?
a. Yes
b. No

Answer:b

Q30.The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a
pointer to a pointer to a integer is
a) int **fun(float**, char**)
b) int *fun(float*, char*)
c) int ***fun(float*, char**)
d) int ***fun(*float, **char)
Answer:c

Q31.What does your class can hold?


a) data
b) functions
c) both a & b
d) none of the mentioned

Answer:c

Q32.How many specifiers are present in access specifiers in class?


a) 1
b) 2
c) 3
d) 4

Answer:c

Q33. Which is used to define the member of a class externally?


a) :
b) ::
c) #
d) none of the mentioned

Answer:b

Q34. Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b

Answer:d

Q35. Which of the following is a valid class declaration?


a) class A { int x; };
b) class B { }
c) public class A { }
d) object A { int x; };

Answer:a

Q36. The fields in the class in c++ program are by default


a) protected
b) private
c) public
d) none of the mentioned

Answer:b

Q37. Constructors are used to


a) initalize the objects
b) construct the data members
c) both a & b
d) none of the mentioned

Answer:a

Q38. When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned

Answer:a

Q39. Where does the object is created?


a) class
b) constructor
c) destructor
d) attributes

Answer:a

Q40. How to access the object in the class?


a) scope resolution operator
b) ternary operator
c) direct member access operator
d) none of the mentioned

Answer:c

Q41. Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b

Answer:d

Q42. Pick out the other definition of objects.


a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class

Answer:d

Q43. How many objects can present in a single class?


a) 1
b) 2
c) 3
d) as many as possible

Answer:d
Q44. Which special character is used to mark the end of class?
a) ;
b) :
c) #
d) $

Answer: a

Q45.The friend functions are used in situations where:

A. We want to have access to unrelated classes


B. Dynamic binding is required
C. Exchange of data between classes to take place
D. None of the above

Answer: D

Q46. The keyword friend does not appear in

A. The class allowing access to another class


B. The class desiring access to another class
C. The private section of a class
D. The public section of a class

Answer: C

Q47.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 mentioned

Answer:a

Q48. Which keyword is used to declare the friend function?


a) firend
b) friend
c) classfriend
d) myfriend

Answer:b

Q49. What is the syntax of friend function?


a) friend class1 Class2;
b) friend class;
c) friend class
d) None of the mentioned

Answer:a

Q50. 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

Q51. Where does keyword ‘friend’ should be placed?


a) function declaration
b) function definition
c) main function
d) None of the mentioned

Answer:a

Q52. the originator of the C++ language


a)Bjarne Stroustrop
b)Dennis Ritchie
c)Mike Sheridan
d)James Gosling

Answer:a

Q53.Where is the derived class is derived from?


a) derived
b) base
c) both a & b
d) None of the mentioned

Answer:b

Q54. Pick out the correct statement.


a) A derived class’s constructor cannot explicitly invokes its base class’s
constructor.
b) A derived class’s destructor cannot invoke its base class’s destructor.
c) A derived class’s destructor can invoke its base class’s destructor.
d) None of the mentioned

Answer:b

Q55. Which of the following can derived class inherit?


a) members
b) functions
c) both a & b
d) None of the mentioned

Answer:c

Q56. Which operator is used to declare the destructor?


a) #
b) ~
c) @
d) $

Answer:b

Q57.An object is composed of:


a.) properties & methods.
b.) events.
c.) properties & events
d.) All of the above.

Answer:d

Q58.Which statement about objects is true?


a.) One object is used to create one class.
b.) One class is used to create one object.
c.) One object can create many classes.
d.) One class can create many objects.
e.) There is no relationship between objects and classes.

Answer: d

Q59.Which feature is needed to make a programming language object oriented?


a.) Encapsulation
b.) Inheritance
c.) Polymorphism
d.) Both a and b.
e.) All of the above.

Answer: e

Q60.We should think of the practice of object-oriented programming as:


a.) a simple answer to the complex problem of creating software.
b.) an incremental improvement to the problem of creating software.
c.) the way to get rid of a werewolf.
d.) Both a and b.
e.) All of the above.

Answer: b

Q61.Encapsulation makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.
e.) All of the above.

Answer: c

Q62.Inheritance makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.
e.) All of the above.

Answer: a

Q63.Polymorphism makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.

Answer: b

Q64.Which element treats as a critical element in the program development in OOP?


a. Data b. function
c. Object d. classes

Answer:a

Q65.OOP uses which approach


a. Top-down
b. bottom-up

Answer: b

Q66.OOP allows us to decompose a problem into a number of entities called


a. Object
b. classes
c. Data
d. Function

Answer:a

Q67. Objects may communicate with each other through


a. Data
b. Methods
c. Object
d. Classes

Answer: b

Q68. New methods & data cab be easily added


a. True
b. false

Answer:a

Q69. Set of objects is called as


a. Class
b. Object
c. Methods
d. Data

Answer:a

Q70. The entire set of data & code of an object can be made which data type using the concept of class
a. User-defined
b. static
c. global
d. derived

Answer:a

Q71. Wrapping up of data & methods into a single unit is called as


a. Inheritance
b. polymorphism
c. Encapsulation
d. Abstraction

Answer:c

Q72. What provide the interface between the object’s data & the program
a. Data
b. class
c. methods
d.Encapsulation

Answer:c

Q73. The insulation of data from direct access by the program is called as
a. Encapsulation
b. Data hiding
c. Private
d. Data Abstraction

Answer:b

Q74. What is the process by which object of one class acquires the properties of object of another class.
a. Encapsulation
b. Data hiding
c. Inheritance
d.Polymorphism

Answer:c

Q75. The concept of inheritance provides the idea of


a. Taking more than one form
b. reusability
c. data hiding
d.modularity

Answer:b

Q76. The derived class is known as


a. Superclass
b. subclass
c. parentclass
d. mainclass

Answer:b

Q77. The class from which the subclass derives the properties is called as
a. mainclass
b. subclass
c. baseclass
d. Superclass

Answer:d

Q78. The property or the ability to take more than one form is called as
a. Encapsulation
b. Polymorphism
c. Inheritance
d. Manyforms

Answer:b

Q79. For what implemention Polymorphism is extensively used?


a. Encapsulation
b. Data hiding
c. Inheritance
d. Methods

Answer:c

Q80. The process of linking of a procedure call with the code to be executed is called as
a. Binding
b. Loading
c. Assembling
d. Debuging

Answer:a

Q81. What is the process in which the code to be linked with the procedure call is not know till execution time
?
a. Binding
b. early binding
c. static binding
d. dynamic binding

Answer:d

Q82. When the code to be linked with the call is known at compile time that situation is called as
a. Binding
b. late binding
c. static binding
d. dynamic binding

Answer:c

Q83. The signature of function is


a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above

Answer: a

Q84. Overloading of constructor function


a) is similar to function overloading
b) different from an overloaded function as it can’t return a value
c) not permitted in C++
d) none of the above

Answer: b
Q85. The binding of a function call at runtime is
a) Static binding
b) Early binding
c) Late binding
d) Runtime binding

Answer: c

Q86. A destruction function


a) Takes no argument and has no return type not even void
b) Has name similar to that of class, preceded by tilde(~) symbol
c) Is used to destruct an object, constructed through constructor function
d) All of the above

Answer: d

Q87. Which of the following statements regarding destructor function is false?


a) Destructors do not accept any arguments, nor do they return any values
b) Destructors can be inherited
c) Member functions may be called from within a destructor
d) Destructor functions are called automatically when an object is destroyed

Answer: b

Q88. Which constructor will initialize the base class data member?
a) derived class
b) base class
c) class
d) None of the mentioned

Answer:b

Q89. A remote control that is used to turn on or off some machine is also called a(n) _____.
a) class
b) interface
c) message
d) instance

Answer:b

Q90. In a student grading system, Student Last Name, Student Address, and Final Course Grade would all be
classified as what?
a)Inheritance
b)Information
c)Encapsulation
d)Polymorphism

Answer:b

Q91. What part of object-oriented technology defines superclass and subclass relationships?
a) Inheritance
b) Scalability
c) Encapsulation
d) Polymorphism

Answer:a

Q92. In a student grading system, objects from different classes communicate with each other. These
communications are known as _____.
a) inheritance
b) polymorphism
c) messages
d) concealment

Answer:c

Q93. When an object has many forms, it has _____.


a) Inheritance
b) Scalability
c) Encapsulation
d) Polymorphism

Answer:d

Q94. What term is used to describe the internal representation of an object that is hidden from view outside the
object's definition?
a) Encapsulation
b) Expandable
c) Polymorphism
d) Inheritance

Answer:a

Q95. What programming language model is organized around "objects" rather than "actions"?
a) Java
b) OOB
c) Perl
d) C+

Answer:b

Q96. What are the instructions called that tell a system what, how, and when to do something?
a) Object-oriented technology approach
b) Object-oriented database
c) Program
d) Database management

Answer:c

Q97. What common technique attempts to save time and energy by reducing redundant work in object-oriented
programming?
a) Reduce lines of programming
b) Reuse of code
c) Reduce size of systems being developed
d) Merging different systems together

Answer:b

Q98. What kind of programming language is Java?


a) Object-oriented programming language
b) Relational programming language
c) Sixth-generation programming language
d) Database management programming language

Answer:a

Q99. Which language is not a true object-oriented programming language?


a.) VB.NET
b.) VB 6
c.) C++
d.) C#

Answer:b

Q100.What are cin and cout?


(A) pointers
(B) functions
(C) operator
(D) stream objects

Answer: D

Q101. What is used to convert the value of one type to another


a. Data type
b. variable
c. typecasting

Answer:a

Q102. How many numbers of java constants are present?


a. 6
b. 4
c. 5
d. 3

Answer:b

Q103. Whaere did Instance and class variables are declare?


a. Inside
b. outside
c. in the main

Answer:a

Q104. Class variables are...... to the class


a. Local
b. static
c. global
d. derived

Answer:c

Q105. Instance variables take .... values for each object


a. Different b. same c. non-zero
Answer:a

Q106. If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
a) protected and public data only in C and B.
b) protected and public data only in C.
c) private data in A and B.
d) protected data in A and B.

Answer:d

Q107. Usually a pure virtual function


a) has complete function body.
b) will never be called.
c) will be called only to delete an object.
d) is defined only in derived class.

Answer:d

Q108. RunTime Polymorphism is achieved by ______


a) friend function
b) virtual function
c) operator overloading
d) function overloading

Answer:b

Q109. In C++, dynamic memory allocation is accomplished with the operator ____
a) new
b) this
c) malloc( )
d) delete

Answer:a

Q110. What type of comments does c++ support?


a) single line
b) multi line
c) single line and multi line
d) none of the mentioned

Answer: c

Q111. A struct is the same as a class except that


a) there are no member functions.
b) all members are public.
c) cannot be used in inheritance hierarchy.
d) it does have a this pointer.

Answer:c

Q112. Pure virtual functions


a) have to be redefined in the inherited class.
b) cannot have public access specification.
c) are mandatory for a virtual class.
d) None of the above.

Answer:a

Q113.Use of virtual functions implies


a) overloading
b) overriding
c) static binding
d) dynamic binding

Answer:d

Q114.Which of the following is false for cin?


a) It represents standard input.
b) It is an object of istream class.
c) It is a class of which stream is an object.
d) Using cin the data can be read from user’s terminal.

Answer:c

Q115.It is possible to declare as a friend


a) a member function
b) a global function
c) a class
d) all of the above

Answer:d

Q116.In multiple inheritance


a) the base classes must have only default constructors
b) cannot have virtual functions
c) can include virtual classes
d) None of the above.

Answer:c

Q117.Identify the operator that is NOT used with pointers


a) ->
b) &
c) *
d) >>

Answer:d

Q118.The members of a class, by default, are


a) public
b) protected
c) private
d) mandatory to specify

Answer:c

Q119.Given a class named Book, which of the following is not a valid constructor?
a) Book ( ) { }
b) Book ( Book b) { }
c) Book ( Book &b) { }
d) Book (char* author, char* title) { }

Answer:b

Q120.Which of the statements is true in a protected derivation of a derived class from a base class?
a) Private members of the base class become protected members of the derived class
b) Protected members of the base class become public members of the derived class
c) Public members of the base class become protected members of the derived class
d) Protected derivation does not affect private and protected members of the derived
class.

Answer:c

Q121.How many constructors can a class have?


a) 0
b) 1
c) 2
d) any number

Answer:d

Q122.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

Q123.RunTime polymorphism is achieved by ___________


a) friend function
b) virtual function
c) operator overloading
d) function overloading

Answer:b

Q124.If there is a pointer p to object of a base class and it contains the address of an object of a
derived class and both classes contain a virtual member function abc(), then the statement
p->abc(); will cause the version of abc() in the __________class to be executed.
a) Base Class
b) Derived class
c) Produces compile time error
d) produces runtime error

Answer:b

Q125.We can output text to an object of class ostream using 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

Q126.Which of the following is not the characteristic of constructor.


a) They should be declared in the public section.
b) They do not have return type.
c) They can not be inherited.
d) They can be virtual.

Answer:d

Q127.Name the header file to be included for the use of built in function isalnum()
a) string.h
b) process.h
c) ctype.h
d) dos.h

Answer:c

Q128.A class defined within another class is:


a) Nested class
b) Inheritance
c) Containership
d) Encapsulation

Answer:a

Q129.The major goal of inheritance in c++ is:


a) To facilitate the conversion of data types.
b) To help modular programming.
c) To extend the capabilities of a class.
d) To hide the details of base class.

Answer:c

Q130.The following can be declared as friend in a class


a) an object
b) a class
c) a public data member
d) a private data member

Answer:b

Q131.A copy constructor takes


a) no argument
b) one argument
c) two arguments
d) arbitrary no. of arguments

Answer:b

Q132.Overloading a postfix increment operator by means of a member function takes


a) no argument
b) one argument
c) two arguments
d) three arguments

Answer:a

Q133.Which of the following ways are legal to access a class data member using this pointer?
a) this.x
b) *this.x
c) *(this.x)
d) (*this).x

Answer:d

Q134.Which of the following declarations are illegal?


a) void *ptr;
b) char *str = “hello”;
c) char str = “hello”;
d) const *int p1;

Answer:c

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


a) ->
b) =
c) ( )
d) *

Answer:d

Q136.If a base class destructor is not virtual, then


a) It can not have a function body.
b) It can not be called.
c) It can not be called when accessed from pointer.
d) Destructor in derived class can not be called when accessed through a pointer to the base
class.

Answer:d

Q137.Which of the following statement is valid?


(A) We can create new C++ operators.
(B) We can change the precedence of the C++ operators.
(C) We can change the associativity of the C++ operators.
(D) We can not change operator templates.

Answer:d

Q138.Which can be passed as an argument to a function?


a) constant
b) expression
c) another function
d) all of the above.

Answer:a

Q139.The operator << when overloaded in a class


a) must be a member function
b) must be a non member function
c) can be both (A) & (B) above
d) cannot be overloaded

Answer:c
Q140.Data members which are static
a) cannot be assigned a value
b) can only be used in static functions
c) cannot be defined in a Union
d) can be accessed outside the class

Answer:b

Q141.this pointer
a) implicitly points to an object.
b) can be explicitly used in a class.
c) can be used to return an object.
d) All of the above.

Answer:d

Q142.The operator that cannot be overloaded is


a) ++
b) ::
c) ( )
d) ~

Answer:b

Q143.A struct is the same as a class except that


a) there are no member functions.
b) all members are public.
c) cannot be used in inheritance hierarchy.
d) it does have a this pointer.

Answer:c

Q.144 What is the use of the indentation in c++?


a) distinguishes between comments and code
b) r distinguishes between comments and outer data
c) both a and b
d) none of the mentioned

Answer: a

Q144.What is a comment in c++?


a) comments are parts of the source code disregarded by the compiler
b) comments are executed by compiler to find the meaning of the comment
c) comments are executable
d) none of the mentioned

Answer: a

Q145. Which of the following is not the member of class?


A. Static function
B. Friend function
C. Const function
D. Virtual function

Answer: B
Q.146. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function

Answer: B

Q.147 How many instances of an abstract class can be created?


A. 1
B. 5
C. 13
D. 0

Answer: D

Q.148 Which of the following cannot be friend?


A. Function
B. Class
C. Object
D. Operator function

Answer: C

Q.149 In structured programming, the problem is divided into various ______.


A. modules
B. functions
C. structures
D. objects

Answer: B

Q.150 Which header file must be included for cin and cout?
(A) stdio.h
(B) conio.h
(C) iostream.h
(D) Both iostream.h and conio.h

Answer: C

Q.151 Which one of the following is correct about the statements given below?

I All function calls are resolved at compile-time in Procedure Oriented Programming.


II All function calls are resolved at compile-time in OOPS.

A. Only II is correct.
B. Both I and II are correct.
C. Only I is correct.
D. Both I and II are incorrect.

Answer: C

Q.152. Use of __________ protects data from inadvertent modifications

A. protect() member function


B. private access specifier
C. class protection operator, @
D. none of these

Answer: B

Q.153 A suitable place to store Class declarations is _______.

A. none of these
B. their own header files
C. Auxiliary .cpp file
D. main .cpp files, along with function definitions

Answer: B

Q.154 Inline Functions are invoked at


A. Run time
B. Compile time
C. Depends on how it is invoked
D. Both b and c above

Answer: B

Q.155 Which of the following is false for cin?


(A)It represents standard input.
(B)It is an object of istream class.
(C)It is a class of which stream is an object.
(D)Using cin the data can be read from user’s terminal

Answer: C

Q156.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

Q157.The smallest individual unit in a program is ………


a) Keyword
b) Identifier
c) Token
d) None of the above

Answer: C

Q.158 What is the associativity of add(+);


a) right to left
b) left to right
c) both of these
d) None of the mentioned

Answer:b

Q.159 Which operator is having the highest precedence in c++?


a) array subscript
b) Scope resolution operator
c) static_cast
d) dynamic_cast

Answer:b

Q160.In C++, the statements are enclosed within


a) parenthesis
b) square brackets
c) curly brackets
d) None of the above

Answer: C

Q161.“H” is an example of
a) character literal
b) string literal
c) variable
d) None of the above

Answer: B

Q.162 y=x=2; in C++ will result in


a) compilation error
b) runtime error
c) assignment of value to x then to y
d) None of the above

Answer: C

Q.163 Modules operator (%) has higher precedence than


a) Divide (/) operator
b) Multiply (*) operator
c) Negation (unary minus)
d) Bitwise left shift operator

Answer: C

Q.164 The result of the following statement is


int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;
a) ans=7, y=7
b) ans=8,y=7
c) ans=8,y=8;
d) none of the above

Answer: C

Q165 Consider the following if construct


If(x=0)
cout<<”Inside loop!”;
cout<<”Outside loop”;
The result of the above code segment is.

a) inside loop
b) outside loop
c) both (a) & (b)
d) none of the above

Answer: B

166. The result of 2 & 3 is


a) 2
b) 3
c) 5
d) none of the above

Answer: A

Q167 The following is a valid statement in C++


a) int x=(int)2.50;
b) int x=int(2.50);
c) Both (a) & (b)
d) None of the above

Answer: C

Q.168 Which of the following operator can be overloaded


a) Member access operator ( . & .*)
b) Conditional operator (?:)
c) Scope resolution operator (::)
d) None of the above

Answer: D

Q.169 When a member function of a class call another member function, it is


a) Nesting of classes
b) Nesting of functions
c) Nesting of objects
d) None of the above

Answer: B

Q.170 Functions can returns


a) arrays
b) reference
c) object
d) all of the above

Answer: D

Q.171 Pick the odd one out


a) array type
b) character type
c) boolean type
d) integer type
Answer:a

Q.172 Which type is best suited to represent the logical values?


a) integer
b) boolean
c) character
d) all of the mentioned

Answer:b

Q.173 Identify the user-defined types from the following?


a) enumeration
b) classes
c) both a and b
d) int

Answer:c

Q174.Which of the following statements are true?


int f(float)
a) f is a function taking an argument of type int and retruning a floating point number
b) f is a function taking an argument of type float and returning a integer.
c) f is a function of type float
d) none of the mentioned

Answer:b

Q.175 Pick the odd one out.


a) integer, character, boolean, floating
b) enumeration, classes
c) integer, enum, void
d) arrays, pointer, classes

Answer:c

Q.176. When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible

Answer:b

Q.177. Is bool a fundamental datatype in C++?


a) Yes
b) No, it is a typedef of unsigned char
c) No, it is an enum of {false,true}
d) No, it is expanded from macros
Answer:a

Q.178 Find the odd one out:


a) std::vector<int>
b) std::vector<short>
c) std::vector<long>
d) std::vector<bool>

Answer:d

Q.179 What is the value of the bool?


bool is_int(789.54)
a) True
b) False
c) 1
d) none of the mentioned

Q.180 What happens when a null pointer is converted into bool?


a) An error is flagged
b) bool value evaluates to true
c) bool value evaluates to false
d) the statement is ignored

Answer:c

Q.181 Which of the following statements are false?


a) bool can have two values and can be used to express logical expressions.
b) bool cannot be used as the type of the result of the function.
c) bool can be converted into integers implicitly
d) a bool value can be used in arithemetic expressions.

Answer:b

Q.182 For what values of the expression is an if-statement block not executed?
a) 0 and all negative values
b) 0 and -1
c) 0
d) 0, all negative values, all positive values except 1

Answer:c

Q.183 Which of the two operators ++ and — work for the bool datatype in C++?
a) None
b) ++
c) –
d) Both

Answer:b

Q.184 What is the output of the following program? 2Marks

#include <iostream>
using namespace std;
int f(int p, int q)
{
if (p > q)
return p;
else
return q;
}
main()
{
int a = 5, b = 10;
int k;
bool x = true;
bool y = f(a, b);
k =((a * b) + (x + y));
cout << k;
}

a) 55
b) 62
c) 52
d) none of the mentioned

Answer:c

Q.185 What is the value of p? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int p;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p = ((x + y) + (a + b));
cout << p;
return 0;
}

a) 0
b) 16
c) 12
d) 2

Answer:b

Q.186 Evaluate the following


(false && true) || false || true
a) 0
b) 1
c) false
d) none of the mentioned
Answer:b

Q.187 How many characters are specified in the ASCII scheme?


a) 64
b) 128
c) 256
d) none of the mentioned

Answer:b

Q.188 Select the right option.


Given the variables p, q are of char type and r, s, t are of int type 2 Marks
1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);
a) 1 is true but 2 is false
b) 1 is false and 2 is true
c) both 1 and 2 are true
d) both 1 and 2 are false

Answer:c

Q.189 How do we represent a wide character of the form wchar_t?


a) L’a’
b) l’a’
c) L[a]
d) la

Answer:a

Q.190 What is the output of this program? 2 Marks

#include <stdio.h>
int main()
{
char a = '\012';

printf("%d", a);
return 0;
}
a) Compiler error
b) 12
c) 10
d) Empty

Answer:c
Q.191 In C++, what is the sign of character data type by default?
a) Signed
b) Unsigned
c) Implementation dependent
d) None of these
Answer:c

Q.192 8. Is the size of character literals different in C and C++?


a) Implementation defined
b) Can’t say
c) Yes, they are different
d) No, they are not different

Answer:c

Q.193 The size_t integer type in C++ is?


a) Unsigned integer of at least 64 bits
b) Signed integer of at least 16 bits
c) Unsigned integer of at least 16 bits
d) Signed integer of at least 64 bits

Answer:c

Q.194 What is the output of the following program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int x = -1;
unsigned int y = 2;

if(x > y) {
cout << "x is greater";
} else {
cout << "y is greater";
}
}
a) x is greater
b) y is greater
c) Implementation defined
d) Arbitrary

Answer:a

Q.195 Which of these expressions will return true if the input integer v is a power of two?
a) (v | (v + 1)) == 0;
b) (v & (v – 1)) == 0;
c) (v | (v + 1)) == 0;
d) (v & (v – 1)) == 0;

Answer:d

Q.196 What is the value of the following 8-bit integer after all statements are executed?
int x = 1; 2 Marks
x = x << 7;
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined
View Answer

Answer:d

Q.197 What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7; 2 Marks
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined

Answer:d

Q.198 Which of these expressions will make the rightmost set bit zero in an input integer x?
a) x = x | (x-1)
b) x = x & (x-1)
c) x = x | (x+1)
d) x = x & (x+1)

Answer:b

Q.199 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)

Answer:c

Q.200 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)

Answer:c

Q.201 What will be the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int a = 8;
cout << "ANDing integer 'a' with 'true' :" << a && true;
return 0;
}
a) ANDing integer ‘a’ with ‘true’ :8
b) ANDing integer ‘a’ with ‘true’ :0
c) ANDing integer ‘a’ with ‘true’ :1
d) None of the mentioned

Answer:a

Q.202 What will be output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << k;
return 0;
}
a) compile time error
b) -1 1
c) 1 -1
d) implementation defined

Answer:b

Q.203 What will be output of this function? 2 Marks

int main()
{
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}
a) 0
b) 1
c) Compiler error may be possible
d) Runtime error may be possible

Answer:c

Q.204 Identify the correct option.


a) enumerators are contants
b) enumerators are user defined types
c) enumerators are unchangables.
d) character

Answer:b

Q.205 In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned

Answer:b

Q.206 To which of these enumerators can be assigned?


a) integer
b) negative
c) enumerator
d) all of the mentioned

Answer:d

Q.207 What will happen when defining the enumerated type?


a) it will not allocate memory
b) it will allocate memory
c) it will not allocate memory to its variables
d) none of the mentioned

Answer:a

Q.208 Which variable does equals in size with enum variable?


a) int variable
b) float variable
c) string variable
d) none of the mentioned

Answer:a

Q.209 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
enum cat {
temp = 7
};
int main()
{
int age = 14;
age /= temp;
cout << "If you were cat, you would be " << age << endl;
return 0;
}
a) If you were cat, you would be 5
b) If you were cat, you would be 2
c) If you were cat, you would be 7
d) none of the mentioned

Answer:b

Q.210 What is the output of this program? 2 Marks


#include <iostream>
using namespace std;
enum test {
A = 32, B, C
};
int main()
{
cout << A << B<< C;
return 0;
}
a) 323334
b) 323232
c) 323130
d) none of the mentioned

Answer:a

Q.211 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
enum colour {
green, red, blue, white, yellow, pink
};
int main()
{
cout << green<< red<< blue<< white<< yellow<< pink;
return 0;
}
a) 0123456
b) 1111111
c) compile time error
d) runtime error

Answer:a

Q.212 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i <= zee; i++) {
printf("%d ", i);
}
return 0;
}
a) 012
b) 123
c) compile time error
d) runtime error
Answer:c

Q.213 What is output of the this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int i;
enum month {
JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
};
for (i = MAR; i <= NOV; i++)
cout << i;
return 0;
}
a) 01234567891011
b) 123456789101112
c) 34567891011
d) 123456789

Answer:c

Q.214 What does your class can hold?


a) data
b) functions
c) both a & b
d) none of the mentioned

Answer:C

Q.215 How many specifiers are present in access specifiers in class?


a) 1
b) 2
c) 3
d) 4

Answer:c

Q.216 Which is used to define the member of a class externally?


a) :
b) ::
c) #
d) none of the mentioned

Answer:b

Q.217 Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b

Answer:d

Q.218. What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class rect
{
int x, y;
public:
void val (int, int);
int area ()
{
return (x * y);
}
};
void rect::val (int a, int b)
{
x = a;
y = b;
}
int main ()
{
rect rect;
rect.val (3, 4);
cout << "rect area: " << rect.area();
return 0;
}
a) rect area:12
b) rect area: 12
c) rect area:24
d) none of the mentioned

Answer:b

Q.219 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class CDummy
{
public:
int isitme (CDummy& param);
};
int CDummy::isitme (CDummy& param)
{
if (&param == this)
return true;
else
return false;
}
int main ()
{
CDummy a;
CDummy *b = &a;
if (b->isitme(a)) {
cout << "execute";
}
else
{
cout<<"not execute";
}
return 0;
}
a) execute
b) not execute
c) none of the mentioned
d) both a & b

Answer:a

Q.220 Which of the following is a valid class declaration?


a) class A { int x; };
b) class B { }
c) public class A { }
d) object A { int x; };

Answer:a

Q.221 The fields in the class in c++ program are by default


a) protected
b) private
c) public
d) none of the mentioned

Answer:b

Q.222 Constructors are used to


a) initalize the objects
b) construct the data members
c) both a & b
d) none of the mentioned

Answer:a

Q.223 When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned

Answer:a

Q.224 Where does the object is created?


a) class
b) constructor
c) destructor
d) attributes

Answer:a

Q.225 How to access the object in the class?


a) scope resolution operator
b) ternary operator
c) direct member access operator
d) none of the mentioned

Answer:c

Q.226 Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b

Answer:d

Q.227 What is the output of the following program? 2 Marks

#include <iostream>
using namespace std;
class Box
{
public :
double length;
double breadth;
double height;
};
int main( )
{
Box Box1;
double volume;
Box1.height = 5;
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;
return 0;
}
a) 210
b) 213
c) 215
d) 217

Answer:b

Q.228 What is the output of the program? 2 Marks


#include <iostream>
using namespace std;
class Rect
{
int x, y;
public:
void set_values (int,int);
int area ()
{
return (x * y);
}
};
void Rect::set_values (int a, int b) {
x = a;
y = b;
}
int main ()
{
Rect recta, rectb;
recta.set_values (5, 6);
rectb.set_values (7, 6);
cout << "recta area: " << recta.area();
cout << "rectb area: " << rectb.area();
return 0;
}
a) recta area: 30 rectb area: 42
b) recta area: 20 rectb area: 34
c) recta area: 30 rectb area: 21
d) none of the mentioned

Answer:a

Q.229 Pick out the other definition of objects.


a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class

Answer:d

Q.230 How many objects can present in a single class?


a) 1
b) 2
c) 3
d) as many as possible

Answer:d

Q.231 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class sample
{
private:
int var;
public:
void input()
{
cout << var;
}
void output()
{
cout << "Variable entered is ";
cout << var << "\n";
}
};
int main()
{
sample object;
object.input();
object.output();
object.var();
return 0;
}
a) Enter an integer 5
Variable entered is 5
b) runtime error
c) error
d) none of the mentioned

Answer:c

Q.232 Pick out the correct syntax of operator conversion.


a) operator float()const
b) operator float()
c) operator const
d) None of the mentioned

Answer:a

Q.233 Which special character is used to mark the end of class?


a) ;
b) :
c) #
d) $

Answer: a

Q.234 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class number
{
int i;
public:
int geti();
void puti(int j);
};
int number::geti()
{
return i;
}
void number::puti(int j)
{
i = j;
}
int main()
{
number s;
s.puti(10);
cout << s.geti( );
return 0;
}
a) 10
b) 11
c) 20
d) 22

Answer:a

Q.235 Which class is used to design the base class?


a) abstract class
b) derived class
c) base class
d) None of the mentioned

Answer:a

Q.236 Which is used to create a pure virtual function ?


a) $
b) =0
c) &
d) !

Answer:b

Q.237 Which is also called as abstract class?


a) virtual function
b) pure virtual function
c) derived class
d) None of the mentioned

Answer:b
Q.238 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class p
{
protected:
int width, height;
public:
void set_values (int a, int b)
{
width = a; height = b;
}
virtual int area (void) = 0;wa
};
class r: public p
{
public:
int area (void)
{
return (width * height);
}
};
class t: public p
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
r rect;
t trgl;
p * ppoly1 = &rect;
p * ppoly2 = &trgl;
ppoly1->set_values (4, 5);
ppoly2->set_values (4, 5);
cout << ppoly1 -> area() ;
cout << ppoly2 -> area();
return 0;
}
a) 1020
b) 20
c) 10
d) 2010

Answer:d

Q.239 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class MyInterface
{
public:
virtual void Display() = 0;
};
class Class1 : public MyInterface
{
public:
void Display()
{
int a = 5;
cout << a;
}
};
class Class2 : public MyInterface
{
public:
void Display()
{
cout <<" 5" << endl;
}
};
int main()
{
Class1 obj1;
obj1.Display();
Class2 obj2;
obj2.Display();
return 0;
}
a) 5
b) 10
c) 5 5
d) None of the mentioned

Answer:c

Q.240 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class sample
{
public:
virtual void example() = 0;
};
class Ex1:public sample
{
public:
void example()
{
cout << "ubuntu";
}
};
class Ex2:public sample
{
public:
void example()
{
cout << " is awesome";
}
};
int main()
{
sample* arra[2];
Ex1 e1;
Ex2 e2;
arra[0]=&e1;
arra[1]=&e2;
arra[0]->example();
arra[1]->example();
}
a) ubuntu
b) is awesome
c) ubuntu is awesome
d) None of the mentioned

Answer:c

Q.241 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class Base
{
public:
virtual void print() const = 0;
};
class DerivedOne : virtual public Base
{
public:
void print() const
{
cout << "1";
}
};
class DerivedTwo : virtual public Base
{
public:
void print() const
{
cout << "2";
}
};
class Multiple : public DerivedOne, DerivedTwo
{
public:
void print() const
{
DerivedTwo::print();
}
};
int main()
{
Multiple both;
DerivedOne one;
DerivedTwo two;
Base *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &one;
array[ 2 ] = &two;
for ( int i = 0; i < 3; i++ )
array[ i ] -> print();
return 0;
}
a) 121
b) 212
c) 12
d) None of the mentioned

Answer:b

Q.242 Pick out the correct option.


a) We cannot make an instance of an abstract base class
b) We can make an instance of an abstract base class
c) Both a & b
d) None of the mentioned

Answer:a

Q.243 Where does the abstract class is used?


a) base class only
b) derived class
c) both a & b
d) None of the mentioned

Answer:a

Q.244 What are the essential operators in c++?


a) +
b) |
c) <=
d) All of the mentioned

Answer:d

Q.245 In which direction does the assignment operation will take place?
a) left to right
b) right to left
c) top to bottom
d) None of the mentioned
Answer:b

Q.246 Pick out the compound assignment statement.


a) a = a - 5
b) a = a / b
c) a -= 5
d) None of the mentioned

Answer:c

Q.247 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
a) a:4 b:7
b) a:10 b:4
c) a:4 b:10
d) None of the mentioned

Answer:a

Q.248 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main ()
{
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}
a) 2
b) 7
c) 9
d) 14

Answer:b
Q.249 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int a = 0;
int b = 10;
if ( a && b )
{
cout << "true"<< endl ;
}
else
{
cout << "false"<< endl ;
}
return 0;
}
a) true
b) false
c) error
d) None of the mentioned

Answer:b

Q.250 Where does the default parameter can be placed by the user?
a) leftmost
b) rightmost
c) both a & b
d) none of the mentioned

Answer:b
Unit 2 : Classes & Objects

Question Bank

AY 2020-21 SEM-II Page 1


MCQ’s on Object & classes
1) Where does the object is created?

A. Class
B. Constructor
C. Destructors
D. Attributes

Ans : A

Explanation: In class, only all the listed items except class will be declared.
2)Constructor is executed when __ _.

A. An object goes out of scope.


B. A class is declared
C. An object is created
D. An object is used
Ans : C

Explanation: Constructor is executed when An object is created.


3)Which of the following is a valid class declaration?

A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
Ans : A

Explanation: Class A { int x; }; is a valid class declaration.


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

A. Default
B. Break
C. Protected
D. Asm
Ans : C

Explanation: Protected keywords is used to control access to a class member


5)Which of the following statements is incorrect?

A. Destructor of base class should always be static


B. Destructor of base class should always be virtual.

AY 2020-21 SEM-II Page 2


C. Destructor of base class should not be virtual.
D. Destructor of base class should always be private.
Ans : B

Explanation: Destructor of base class should always be virtual statements is incorrect


6)Which operator can not be overloaded?

A. +
B. ::
C. -
D. *
Ans : B

Explanation: :: operator can not be overloaded


7)What is the size of empty class?

A. 0
B. 2
C. 4
D. 1
Ans : D

Explanation: When we create object of empty class at that time State of that object is nothing.
Behaviour of that object is also nothing, but compiler assigns a unique address to that object.
Memory in Computer is always organized in the form of bytes and minimum memory available at
object address location is 1 byte. That's why size of object of empty class is 1 byte.
8) How to access the object in the class?

A. Ternary operator
B. Scope resolution operator
C. Direct member access operator
D. None of the above
Ans : C

Explanation: Objects in the method can be accessed using direct member access operator which is
(.).
9) When struct is used instead of the keyword class means, what will happen in the program?

A. Access is public by default


B. Access is private by default
C. Access is protected by default
D. None of the mentioned

AY 2020-21 SEM-II Page 3


Ans : A

Explanation: Access is public by default will happen Whenstruct is used instead of the keyword
class.
10) Which of the following is not a member of class?

A. Static Function.
B. Friend Function
C. Const Function
D. Virtual Function

Ans : B

Explanation: Friend function is not a member of class.


11) Which of the following cannot be passed to a function in C++ ?
(A) Constant
(B) Structure
(C) Array
(D) Header file

Answer: (D)

Explanation: Header file can not be passed to a function in C++. While array, constant and
structure can be passed into a function.
So, option (D) is correct.
12) Which of the following is not a correct statement?
(A) Every class containing abstract method must be declared abstract.
(B) Abstract class can directly be initiated with ‘new’ operator.
(C) Abstract class can be initiated.
(D) Abstract class does not contain any definition of implementation.

Answer: (B)

Explanation:
• Every class containing abstract method must be declared abstract. Correct Declaration is
required.
• Abstract class can directly be initiated with ‘new’ operator. No it can’t be initiated directed by
only ‘new’ operator. So, it is Inorrect
• Abstract class can be initiated.Correct
• Abstract class does not contain any definition of implementation.Correct
So, option (B) is correct.

AY 2020-21 SEM-II Page 4


13) Which of the following is true?
(A) All objects of a class share all data members of class
(B) Objects of a class do not share non-static members. Every object has its own copy.
(C) Objects of a class do not share codes of non-static methods, they have their own copy
(D) None of the above

Answer: (B)

Explanation: Every object maintains a copy of non-static data members. For example, let
Student be a class with data members as name, year, batch. Every object of student will have its
own name, year and batch. On a side note, static data members are shared among objects.
All objects share codes of all methods. For example, every student object uses same logic to find
out grades or any other method.
14) A member function can always access the data in _______ _ , (in C++).
(A) the class of which it is member
(B) the object of which it is a member
(C) the public part of its class
(D) the private part of its class

Answer: (A)

Explanation: A member function can access it’s class member variables, irrespective of the
access specifier in which the member variable is declared.So, a member function can always
access the data in the class of which it is a member.
So, option (A) is correct.
15) Data members and member functions of a class in C++ program are by default

A. protected
B. public
C. private
D. None
View Answer
Answer: C
16) Which operator is used to allocate an object dynamically of a class in C++?

A. Scope resolution operator


B. Conditional operator
C. New operator
D. Membership access
Answer: C
17) Which is used to define the member function of a class externally?

A. :

AY 2020-21 SEM-II Page 5


B. ::
C. #
D. None
Answer: B
18) By default functions available in C++ language are

A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
E. All
Answer: E
19) When you create an object of a class A like A obj ; then which one will be called
automatically

A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
Answer: A
20) The class in C++ which act only as a base class and object of it cannot be created is

A. parent class
B. super class
C. abstract class
D. none of the above
Answer: C

Q.001 Instance of which type of class can’t be created?


A Anonymous class
B Nested class
C Parent class
D Abstract class
Correct D

Q.002 What is the scope of a class nested inside another class?


A Protected scope
B Private scope
C Global scope
D Depends on access specifier and inheritance used
Correct D

AY 2020-21 SEM-II Page 6


Q.003 The object can’t be _ _
A Passed by reference
B Passed by value
C Passed by copy
D Passed as function
Correct D

Q.004 If class A has add() function with protected access, and few other members in public.
Then class B inherits class A privately. Will the user will not be able to call __
from the object of class B.
A Any function of class A
B The add() function of class A
C Any member of class A
D Private, protected and public members of class A
Correct D
Q.005 If an abstract class has all the private members, then _
A No class will be able to implement members of abstract class
B Only single inheritance class can implement its members
C Only other enclosing classes will be able to implement those members
D No class will be able to access those members but can implement.
Correct A
Q.006 If the protected members are to be made accessible only to the nearest subclass and no
further subclasses, which access specifier should be used in inheritance?
A The sub class should inherit the parent class privately
B The sub class should inherit the parent class as protected
C The sub class should inherit the parent class as public
D The sub class can use any access modifier
Correct A
Q.007 Except constructors, if all the members are defined in protected specifier then ___
A Instance of class can’t be created
B Instance of class can be created anywhere
C Instance of class can be created only in subclasses
D Instance of class can be created only in main() function
Correct B
Q.008 If protected inheritance is used then _
A Public members become public in subclass
B Protected members become public in subclass
C Protected members become protected in subclass
D Protected and Public members become protected in subclass
Correct D

AY 2020-21 SEM-II Page 7


Q.009 Which among the following is correct to call a private member from outside the class?
A object.memberfunction( parameters );
B object->memberfunction( parameters );
C object->memberfunction( parameteres); or object.memberfunction( parameters );
D Not possible
Correct D
Q.010 Which among the following is true?
A Private member functions can’t be overloaded
B Private member functions can be overridden
C Private member functions can’t be overloaded with a public member
D Private member function can’t be overridden
Correct D
Q.011 Which among the following is correct?
A Private specifier must be used before public specifier
B Private specifier must be used before protected specifier
C Private specifier must be used first
D Private specifier can be used anywhere in class
Correct D
Q.012 Which among the following can be used for outermost class access specifier in java?
A Private
B Public
C Default
D Default or Public
Correct D
Q.013 Which among the following for public specifier is false?
A The static members can’t be public
B The public members are available in other packages too
C The subclasses can inherit the public members privately
D There can be only one public class in java program
Correct A
Q.014 To create a pointer to a private data member of a class, outside the class, which among
the following is correct?
A Return the address of the private data member using a member function
B Access the private member using a pointer outside class
C Declare the member as pointer inside the class
D Not possible to create pointer to a private member
Correct A
Q.015 All the member functions of local classes are ___ _ by default.
A Static
B Inline

AY 2020-21 SEM-II Page 8


C Abstract
D Virtual
Correct C
Q.016 A static nested class is ____ class in behavior that is nested in another _ _ class.
A Top level, top level
B Top level, low level
C Low level, top level
D Low level, low level
Correct A
Q.017 What is the type of elements of array of objects?
A Class
B Void
C String
D Null
Correct A
Q.018 The Object array is created in ___
A Heap memory
B Stack memory
C HDD
D ROM
Correct A
Q.019 Can a super class object give reference to a subclass method?
A No, it is not possible
B Maybe, it is possible
C No, it’s not possible
D No, It’s not possible in few cases only

Correct C
Q.031 What is the role of a constructor in classes?
A To modify the data whenever required
B To destroy an object
C To initialize the data members of an object when it is created
D To call private functions from the outer world
Correct C
Q.032 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 9


A 5
B 55
C Error
D Segmentation Fault
Correct C
Q.033 How constructors are different from other member functions of the class?
A Constructor has the same name as the class itself
B Constructors do not return anything
C Constructors are automatically called when an object is created
D All of the mentioned
Correct D
Q.034 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 10


A B's Constructor called
B's Constructor called
B B's Constructor called
A's default constructor called
B's Constructor called
A's default constructor called
C A's default constructor called
B's Constructor called
A's default constructor called
B's Constructor called
D A's default constructor called
B's Constructor called
A's copy Constructor called
Correct C

Q.035 What is the role of destructors in Classes?


A To modify the data whenever required
B To destroy an object when the lifetime of an object ends

AY 2020-21 SEM-II Page 11


C To initialize the data members of an object when it is created
D To call private functions from the outer world
Correct B
Q.036 What is syntax of defining a destructor of class A?
A A(){}
B ~A(){}
C A::A(){}
D ~A(){};
Correct B
Q.037 In case of operator overloading, operator function must be _ _.
1. Static member functions
2. Non- static member functions
3. Friend Functions
A Only 2
B Only 1, 3
C Only 2 , 3
D All 1 , 2, 3
Correct C
Q.038 In case of binary operator overloading with member function, which of following
statement should be taken into consideration?
A Right hand operand must be object.
B Left hand operand must be object.
C Both the operands must be objects.
D All of these should be considered.
Correct B
Q.039 Given the following C++ code. How would you define the < operator for Box class so
that when boxes b1 and b2 are compared in if block the program gives correct result?

AY 2020-21 SEM-II Page 12


A bool operator<(Box b)
{
return this->capacity <b.capacity ? true : false;
}
B bool operator<(Box b)
{
return this->capacity >b.capacity ? true : false;
}
C bool operator<(Box b)
{
return b1 > b2 ? true : false;
}
D bool operator<(Box b)
{
return this <b ? true : false;
}
Correct A
Q.040 Which is the correct example of a unary operator?
A &

AY 2020-21 SEM-II Page 13


B ==
C -
D /
Correct C
Q.041 Which is called ternary operator?
A ?:
B &&
C |||
D ===
Correct A
Q.042 In case of inheritance where both base and derived class are having constructors, when
an object of derived class is created then_ .
A constructor of derived class will be invoked first
B constructor of base class will be invoked first
C constructor of derived class will be executed first followed by base class
D constructor of base class will be executed first followed by derived class
Correct D
Q.043 When a child class inherits traits from more than one parent class, this type of
inheritance is called ____ _ inheritance.
A Hierarchical
B Hybrid
C Multilevel
D Multiple
Correct D
Q.044 When a base class is privately inherited by the derived class, then_ .
A protected members of the base class become private members of derived class
B public members of the base class become private members of derived class
C both a and b
D only b
Correct C
Q.045 class X, class Y and class Z are derived from class BASE. This is____ inheritance.
A Multiple
B Multilevel
C Hierarchical
D Single
Correct C
Q.046 What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class student

AY 2020-21 SEM-II Page 14


{
public:
int rno , m1 , m2 ;
void get()
{
rno = 15, m1 = 10, m2 = 10;
}
};
class sports
{
public:
int sm;
void getsm()
{
sm = 10;
}
};
class statement:publicstudent,public sports
{
int tot,avg;
public:
void display()
{
tot = (m1 + m2 + sm);
avg = tot / 3;
cout<< tot;
cout<< avg;
}
};
int main()
{
statement obj;
obj.get();
obj.getsm();
obj.display();
}
A 3100
B 3010
C 2010
D 1010
Correct B
Q.047 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 15


A 1
B 0
C Segmentation Fault
D Error
Correct D
Q.048 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 16


A a: 1
B a: 0
C Error
D Segmentation fault
Correct A
Q.049 What will be the output of the following C++ code?

A Error

AY 2020-21 SEM-II Page 17


B Segmentation fault
C a: 1
D a: 0
Correct A
Q.050 When base class is derived in protected mode, then_ .
1. public members of base class become private members of derived class.
2. public members of base class become protected members of derived class.
3. public members of base class become public members of derived class.
4. protected members of base class become protected members of derived class.
5. protected members of base class become private members of derived class.
6. protected members of base class become public members of derived class.
A Only 1, 5
B Only 1, 6
C Only 2, 6
D Only 2, 4
Correct D

UNIT II MCQ

1. Which of the following is not a type of constructor?


A. Copy constructor

B. Friend constructor

C. Default constructor

D. Parameterized constructor
Answer: Option B

3. 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: Option B

4. Which of the following is not the member of class?


A. Static function

AY 2020-21 SEM-II Page 18


B. Friend function

C. Const function

D. Virtual function
Answer: Option B

5. 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: Option C

6. Which of the following term is used for a function defined inside a class?
A. Member Variable

B. Member function

C. Class function

D. Classic function
Answer: Option B

7. Which of the following concept of oops allows compiler to insert arguments in a function
call if it is not specified?
A. Call by value

B. Call by reference

C. Default arguments

D. Call by pointer
Answer: Option C

8. How many instances of an abstract class can be created?


A. 1

B.5

C. 13

D. 0

AY 2020-21 SEM-II Page 19


Answer: Option D

9. Which of the following cannot be friend?


A. Function

B. Class

C. Object

D. Operator function
Answer: Option C

11. A function that is called automatically each time an object is destroyed is a?


(a) Destructor
(b.) Destroyer
(c.) Remover
(d.) Terminator

Answer: Option a

13. True/False: A class can serve as base class for many derived classes.

Answer: True

14. When a class serves as base class for many derived classes, the situation is called:
a. polymorphism
b. hierarchical inheritance
c. hybrid inheritance
d. multipath inheritance

e. none of these

Answer: (b)

15. When two or more classes serve as base class for a derived class, the situation is known as
_ .

a) multiple inheritance
b) polymorphism

AY 2020-21 SEM-II Page 20


c) encapsulation

d) hierarchical inheritance
e) none of these

Answer: (a)
16. Which of the following statement is correct?
A. A constructor is called at the time of declaration of an object.

B. A constructor is called at the time of use of an object.

C. A constructor is called at the time of declaration of a class.

D. A constructor is called at the time of use of a class.

Answer: Option A

17. Which of the following functions are performed by a constructor?


A. Construct a new class
B. Construct a new object

C. Construct a new function

D. Initialize objects
Answer: Option D

21. Which of the following is correct about the statements given below?
All operators can be overloaded in C++.
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: Option B

22. What happens if the base and derived class contains definition of a function with same
prototype?
A. Compiler reports an error on compilation.

AY 2020-21 SEM-II Page 21


B. Only base class function will get called irrespective of object.

C. Only derived class function will get called irrespective of object.


D. Base class object will call base class function and derived class object will call derived
class function.
Answer: Option D

24. Which of the following is not a type of inheritance?


A. Multiple

B. Multilevel
C. Distributive

D. Hierarchical
Answer: Option C

25. Which of the following statements regarding inline functions is correct?


A. It speeds up execution.

B. It slows down execution.


C. It increases the code size.

D. Both A and C.
Answer: Option D

27. Which of the following operators cannot be overloaded?


A. []

B. ->
C. ?:

D. *
Answer: Option C

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


A. overload

B. operator
C. friend

AY 2020-21 SEM-II Page 22


D. override
Answer: Option B

30. Which inheritance type is used in the class given below?


class A : public X, public Y
{}
A. Multilevel inheritance
B. Multiple inheritance

C. Hybrid inheritance

D. Hierarchical Inheritance
Answer: Option B

32. Which of the following is an invalid visibility label while inheriting a class?
A. public
B. private

C. protected

D. friend
Answer: Option D

33. Which of the following provides a reuse mechanism?


A. Abstraction
B. Inheritance

C. Dynamic binding
D. Encapsulation
Answer: Option B

34. Which of the following statement is correct?


A. Class is an instance of object.
B. Object is an instance of a class.

C. Class is an instance of data type.


D. Object is an instance of data type.

AY 2020-21 SEM-II Page 23


Answer: Option B

35. When a function is defined inside a class, this function is called ………….
A) Inside function
B) Class function
C) Inline function
D) Interior function

Answer C) Inline function

36. Which of the following cannot be passed to a function?


A) Reference variable
B) Arrays
C) Class objects
D) Header files

Answer D) Header files

37. State true of false.


i) We cannot make the function inline by defining a function outside the class.
ii) A member function can be called by using its name inside another member function of the same
class, this is known as nesting of member function.
A) True, True
B) True, False
C) False, True
D) False, False
Answer C) False, True

38. Which of the following operators could be overloaded?


A) Size of
B) +
C) +=
D) ::

Answer B) +

39. Which of the following is true about the static member variable in C++.
i) It is initialized to zero when the first object of its class is created. Other initialization is also
permitted.
ii) It is visible only within the class, but its lifetime is the entire program.
A) i-True, ii-True
B) ii-False, ii-True
C) i-True, ii-False
D) i-False, iii-False

AY 2020-21 SEM-II Page 24


Answer B) ii-False, ii-True

40. Which of the following keywords are used to control access to a class member?
A) default
B) break
C) protected
D) goto

Answer C) protected

41. What will be the values of x, m and n after execution of the following statements?

Int x, m, n;
m=10;
n=15;
x= ++m + n++;

A) x=25, m=10, n=15


B) x=27, m=10, n=15
C) x=26, m=11, n=16
D) x=27, m=11, n=16

Answer C) x=26, m=11, n=16

42. 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 re usability of code
D) To extend the capabilities of a class

Answer C) To facilitate the reusability of code

43. A variable is defined within a block in a body of a function. Which of the following are true?
A) It is visible throughout the function.
B) It is visible from the point of definition to the end of the program.
C) It is visible from the point of definition to the end of the block.
D) It is visible throughout the block.

Answer D) It is visible throughout the block.

47. What is inheritance?


A. Inheritance allows one class to reuse the state and behavior of another class.
B. It deals with dangling pointers

AY 2020-21 SEM-II Page 25


C. It deals with void pointers
D. It is type of class declaration
Answer: Option A

48. Constructor is
A. A class automatically called whenever a new object of this class is created
B. A class automatically called whenever a new object of this class is destroyed
C. A function automatically called whenever a new object of this class is created
D. A function automatically called whenever a new object of this class is destroyed
Answer: Option C

51. What happens when we try to compile the class definition in following code snippet?

class Birds {};


class Peacock : protected Birds {};

A. It will not compile because class body of Birds is not defined.

B. It will not compile because class body of Peacock is not defined.

C. It will not compile because a class cannot be protectedly inherited from other class.

D. It will compile succesfully.

Answer: Option D

52. Which of the following statements is incorrect?


A. Friend keyword can be used in the class to allow access to another class.

B. Friend keyword can be used for a function in the public section of a class.

C. Friend keyword can be used for a function in the private section of a class.

D. Friend keyword can be used on main().

Answer: Option D

AY 2020-21 SEM-II Page 26


54. Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?
A. A class member and a class object.

B. A class object and a class.

C. A class and a member of that class.

D. A class object and a member of that class.

Answer: Option D

56. How can we make a class abstract?


A. By making all member functions constant.

B. By making at least one member function as pure virtual function.

C. By declaring it abstract using the static keyword.

D. By declaring it abstract using the virtual keyword.

Answer: Option B

57. Which of the following statements is correct when a class is inherited publicly?
A. Public members of the base class become protected members of derived class.

B. Public members of the base class become private members of derived class.

C. Private members of the base class become protected members of derived class.

D. Public members of the base class become public members of derived class.

Answer: Option D

58. Which of the following statements is correct about the constructors and destructors?

AY 2020-21 SEM-II Page 27


A. Destructors can take arguments but constructors cannot.

B. Constructors can take arguments but destructors cannot.

C. Destructors can be overloaded but constructors cannot be overloaded.

D. Constructors and destructors can both return a value.

Answer: Option B

59. Which of the following access specifies is used in a class definition by default?
A. Protected

B. Public

C. Private

D. Friend

Answer: Option C

60. Which of the following statement is correct with respect to the use of friend keyword inside a
class?
A. A private data member can be declared as a friend.

B. A class may be declared as a friend.

C. An object may be declared as a friend.

D. We can use friend keyword as a class name.

Answer: Option B

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

AY 2020-21 SEM-II Page 28


A. Default

B. Break

C. Protected

D. Asm

Answer: Option C

62. Which of the following is false with respect to inheritance?


[A] When a base class is privately inherited, public members of the base class become private
members of the derived class
[B] When a base class is publicly inherited, public members of the base class becomes public
members of derived class
[C] When a base class is privately inherited, a private member of base class becomes private
member of derived class
[D] When a base class is publicly inherited protected members of base class becomes protected
members of derived class
Answer: C. when a base class is privately inherited, a private member of base class becomes
private member of derived class
65. If a base class member access is public, and an inherited class accesses specifier is private,
which of the following statement is true ?
[A] The base class member can be accessed by derived class objects
[B] The base class members cannot be accessed by the derived class members
[C] The derived class members can be accessed by the base class objects
[D] None of above
Answer: A. The base class member can be accessed by derived class objects

69. What is meant by multiple inheritance?


[A] Deriving a base class from derived class
[B] Deriving a derived class from base class
[C] Deriving a derived class from more than one base class
[D] None of the mentioned

AY 2020-21 SEM-II Page 29


Answer: C. Deriving a derived class from more than one base class

71. what is Hybrid Inheritance?


[A] multiple inheritance
[B] multilevel inheritance
[C] multipath inheritance
[D] combination of a and b
[E] combination of a and c
Answer: D. combination of a and b

73.. What is required in inheritance to initialize the data members of the base class through derived
class?

A) Object declaration

B) Destructor

C) Constructor

D) Inheritance

Answer:C) Constructor

75. Which of the statements is true in a protected derivation of a derived class from a base class?

A) Private members of the base class become protected members of the derived class

B) Protected members of the base class become public members of the derived class

C) Public members of the base class become protected members of the derived class

D) Protected derivation does not affect private and protected members of the derived class

AY 2020-21 SEM-II Page 30


Answer:C) Public members of the base class become protected members of the derived
class

76. When the access specifier of the base class in the derived class definition is public, the base
class is ..

A) Publicly inherited

B) Protectedly inherited

C) Privately inherited

D) None of the above


Answer:A) Publicly inherited

79. The constructor and the destructor of a class are automatically invoked when memory is
allocated and deallocated to an ....

A) Data type

B) Copy constructor

C) Object

D) None of the above

Answer:C) Object

80. A pure virtual function is a virtual function that

A) has no body

B) returns nothing

C) is used in base class

D) both (A) and (C)

Answer:D) both (A) and (C)

AY 2020-21 SEM-II Page 31


81. A class defined within another class is

A) Nested Class

B) Inheritance

C) Containership

D) Encapsulation
Answer:A) Nested Class

82. Which variable stores the memory address of another variable?

A) Reference

B) Pointer

C) Array

D) None of the above

Answer:B) Pointer

83. Which of the following correctly declares an array?


a) int array[10];
b) int array;
c) array{10};
d) array array[10];

Answer:a
Explanation:Because array variable and values need to be declared after the datatype only.

84. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined

Answer:b
Explanation:Because the first element always starts at 0. So it is on 8 position.

AY 2020-21 SEM-II Page 32


85. What is a array?
a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same type placed in non-contiguous memory locations
d) None of the mentioned

Answer:a
Explanation:None.

86. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;

Answer:a
Explanation:The array location starts from zero, So it can accessed by array[6].

87. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;

Answer:d

88. What will be the output of this program?

#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++) {
result += array1[temp];
}
for (temp = 0; temp < 4; temp++) {
result += array2[temp];
}
cout << result;
return 0;
}

AY 2020-21 SEM-II Page 33


a) 6553
b) 6533
c) 6522
d) 12200

Answer:b

Explanation:In this program we are adding the every element of two arrays. Finally we got output
as 6533.
Output:
$ g++ array.cpp
$ a.out
6533

89. What will be the output of the this program?

#include <stdio.h>
using namespace std;
int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++) {
result += array[n];
}
cout << result;
return 0;
}

a) 25
b) 26
c) 27
d) None of the mentioned

Answer:d
Explanation:We are adding all the elements in the array and printing it. Total elements in the
array is 7, but our for loop will go beyond 7 and add a garbage value.

91. What is the output of this program?

#include <stdio.h>
using namespace std;
int main()
{

AY 2020-21 SEM-II Page 34


char str[5] = "ABC";
cout << str[3];
cout << str;
return 0;
}

a) ABC
b) ABCD
c) AB
d) None of the mentioned

Answer:a
Explanation:We are just printing the values of first 3 values.
$ g++ array.cpp
$ a.out
ABC

99. Which among following is correct way of declaring object of a class ?

A. Classname Objectname;
B. Class Classname Objectname;
C. Class Classname Object Objectname;
D. Classname Object Objectname;

Answer: Option A

100. A Variable __ of void type.

A. May be declared

B. Can be initialized

C. Cannot be intialized

D. Cannot be declared

Answer: Option D

AY 2020-21 SEM-II Page 35


AY 2020-21 SEM-II Page 36
QN. QUESTION OPTION A OPTION B OPTION C OPTION D

1 Which of the following term is used for a Member Variable Member function Class function Classic function
function defined inside a class?
2 Classes are useful because they are removed from permit data to be hidden bring together all aspects can closely model
memory when not in use from other classes of an entity in one place objects in the real
world
3 Which member function of class cannot friend functions Private member functions Constant member Static member
modify its objects attributes ? functions functions
4 Which of the following is an abstract data int double string Class
type?
5 Which of the following statement is correct? Object is an instance of a Class is an instance of data Object is an instance of Class is an instance
class. type. data type. of object
6 Which of the following is correct about class class can have member class data members are Pointer to structure or class data members
and structure? functions while structure public by default while classes cannot be are private by
cannot. that of structure are private declared. default while that of
structure are public
by default.
7 What does your class can hold? Data Functions Both A & B None of the above
8 What is object in C++ ? Object is function of a Object is an instance of a Object is datatype of a Object is part of
class. class. class. syntax of a class
9 How many specifier are present as access 1 2 3 4
specifier in a class in C++?
10 Which operator is used to define the member : :: # None Of The
of a class externally? Mentioned
11 Which of the following is a valid class class A { int x; }; class B { } public class A { } object A { int x; };
declaration?

12 The fields in the class in c++ program are by protected private public none of the
default mentioned
13 What is class in c++ ? When you define a class, When you define a class, A. When you define a When you define a
you define a blueprint for you add more class, you define class, you make
a data type functionality. the logic. debugging.

14 ‘cin’ is __ a Class an Object a Package Namespace

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 37


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

15 Operators such as ....................... cannot be + ++ :: ==


overloaded.
16 Which of the following is the inequality != = == A) -->
operator?
17 The preprocessor directive always starts % # & “”
with the symbol
18 Which operator is used to define member : :: * Extern
function outside of a class in c++?
19 The if-else statement can be replaced by Bitwise operator * Conditional operator None of these
which operator? (?:)

20 The new operator returns a pointer to the creates a variable called obtains memory for a tells how much
variable new new variable memory is
available

21 Which of the following is the boolean | & && |&


operator for logical-and?
22 The operator that cannot be overloaded is ++ A) :: () A) ~

23 Which of the following is the correct := = equal ==


operator to compare two variables?

24 ::count means ----- Local version of the Global version of the Both local and global All of these
variable count variable count version of count
25 The scope resolution operator is a semicolon(;) a colon(:) two colons(::) a comma(,)

26 Which refrence modifier is used to define & $ # none of the


reference variable? mentioned

27 Which of the following is not a member- * ::* ->* ::


dereferencing operator?

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 38


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

28 Which operator is used to resolve the −> . * ::


scope of the global variable?
29 Which of the following operators allow :: ? :? %
defining the member functions of a class
outside the class?
30 What is the stored in the object obj in Memory address of NULL Any arbitrary pointer Garbage
following lines of code? allocated memory of
box obj; object.
31 Classes are useful, because they can closely model they permit data to be bring all aspects together none of these
objects in real world hidden from other classes as a one entity
32 In C++ the function contained in the class is member function procedure class function none of these
called __
33 _ _ is a special character used to mark the : ; # $
end of class.
34 Which of the following is called instance of function friend function object member variable
the class ?
35 The class holds _. functions data both A and B none of these
36 Choose the valid class declaration. class {} Classes {int a;} public class A {} none of these

37 Instead of the class if use struct then _ _. access in the public by access is private by default access is protected by none of these
default default
38 choose the correct statement. only data members are only member functions both data and member . the member
private are public functions can be public functions are private
39 Which of the following is not validity access public private protected extern
specifier in the class ?
40 A class cannot be _ _. virtual friend generic inline
41 What is the purpose of keyword inline? it allows one line function . it causes the replacement it indicates the function it tells compiler to
declaration of function calls by the declaration use that function in
code from the function the same source
code file
42 Which of the following is a valid inline public private protected extern
function 'myfun'?

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 39


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

43 inline void myfun() void myfun() inline inline:: void none of these
{//functon code} {//function code} myfun{//function code}
44 Following is a main benefit of the inline it decrease the size of the it simplifies the source it increases the speed of it removes
function/ program code the resulting program unnecessary
function
45 Following is a limit on inline function. inline function can not inline function has to inline function must have the compiler can
return a values return a value less than 10 lines of code choose to ignore an
inline directive.
46 When will you make a function inline? if that function is small . if the function is small if the function is not if the function is not
and not called frequently but called frequently small but called small and not called
frequently frequently
47 The fields in class of C++ program are _ _. . public private protected none of these
48 Which of the following keyword is used to const switch private for
control the access of data members of a class
?

49 What arrays in the C++? . A series of elements of A series of elements of A series of elements of A series of elements
same type placed in different type placed in same type placed in non- of different type
continuous block of continuous block of continuous block of placed in non-
memory memory memory continuous block of
memory
50 The memory address for array can be obtained a[0] address_of(a) a[1] a
using .
51 What is the output of the following code? 42 30 garbage value syntax error
#include <iostream>
using namespace std;
class Test
{
private
int array[]={0,2,4,6,8,10,12};
public:
void computer();
};
void Test::compute()

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 40


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

{
int result=0;
for (int i=0;i<7;i++)
{
result+=array[i];
}
cout<<result;
}
int main()
{
test obj;
obj.compute();
return();
}
52 The size of heap memory is _ _. 100 MB 1024 MB 1024 GB determined by size
of RAM and swap
memory
53 How will you pass the large objects in C++? using call by value using call by reference either a or b none of these
method method
54 Objects of the same class shres the values of global variables and static non static and static static variables, non static local and static
_ and maintain separate values for _. variables variables
55 Which of the member functions of class private member functions constant member functions friend function static member
cannot modify its objects attributes ? function
56 How many types of classes are there? 1 2 3 4
57 How to access object in the class? using ternary operator using direct member scope resolution operator none of these
access operator
58 Constructors are used . to build a user interface deallocate memory initialize newly created to construct
objects functions
59 Which of the following member is not public private protected both B and C
accessible using the direct member access
operator?
60 If different objects are created the separate data members member functions both A ans B none of these
memory space is created for .

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 41


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

61 The memory required by any objects is size of non static data order of data members Byte padding all of these
dependent upon following factors members of the class

62 Which of the following is correct way of Class_name object_name; object_name class_name class class_name class class_name
declaring object of a class ? object_name object object_name
63 What is the output of the following code? 10 constructor invoked syntax error none of these
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test(int x);
};
test::test(int x=10)
{
a=x;
cout<<"\n Constructor Invoked";
}
int main()
{
test obj1,*obj2;
return 0;
}
64 How many objects can be created by a single 1 2 3 as many as required
class?
65 The name of the constructor is . limited to 10 character same as the belonging main as per the
class name programmer's choice
66 What is the output of the following code? Constructor syntax error constructor copy constructor
#include <iostream> copy constructor copy constructor copy constructor
using namespace std; copy constructor constructor copy constructor
class test
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 42


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

private:
int a;
public:
test(int x);
test(test &);
};
test::test(int x=10)
{
a=x;
cout<<"\n CopyConstrustor";
}
int main()
{
test*obj1,*obj2;
obj1=new test (10);
obj2=new test(*obj1);
test *obj3;
obj3=new test(20);
return 0;
}

67 What is the output of the following code? 012 000 three garbage values syntax error
#include<iostream> .
using namespace std;
class test
{
private:
int a;
public:
test(int x)
void display();
};
test::test(int i)
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 43


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

a=i;
}
void test::display()
{
cout<<""<<a;
}
int main()
{
test obj[3];
obj[0].display();
obj[1].display();
obj[2].dispaly();
return 0;
}
68 What is the output of the following code? constructor constructor constructor destructor constructor constructor no output
#include<iostream> destructor destructor
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
cout<<"constructor";
}
~test()
{
cout<<"destructor";
}
};
int main()
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 44


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

test a[2];
return 0;
}
69 What is the output of the following code? 0 1 garbage value syntax error
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
count++;
}
void display()
{
cout<count;
}
};
int main()
{
test obj;
obj.display();
return 0;
}
70 What will be the output of the following syntax error nothing will be displayed Constructor destructor Constructor
code? constructor
class test
{
public:
test()
{cout< "constructor";}

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 45


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

~test()
{cout< "destructor";}
};
int main()
{
delete new test();
return 0;
}
71 The default constructor accepts _ one two three no
parameters.
72 If the default constructor is not defined then . it will cause syntax error it will cause runtime error the compiler will create none of these.
_ _ constructor for creating
an object
73 A class is not having default constructor but the desired object will get it will cause syntax error it will cause runtime error none of these
one parameterized constructor. created because compiler
We have created an object that needs zero will create an inplicit
argument constructor. What will happen in default constructor.
this case?.
74 The destructor is preceded by the symbol # ! ~ $
_
75 The constructors and destructors for an by making explicit call to when object enters and when inheritance occurs none of these
automatic object are invoked . constructor and destructor leaves its scope
functions
76 For copying the object of same class type default constructor dynamic constructor when inheritance occurs none of these
following type of constructor is defined
_
77 Which of the following is true about only I I,III and IV I and II I,II and III
constructor?
I. Constructor have same name as its class
name.
II. They constructors can be inherited
III. The constructor cannot be declared in
protected section.
IV. Constructor cannot return values.

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 46


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

78 Which of the following is not true about only I I and II I and III I,II and III
destructor?
I. It is preceded by dollar sign
II. It can be declared in private section
III. It can be parameterized
79 Object can be defined as _. attribute of class instance of a class member of a class none of these
80 The copy constructor _. creates an object from creates an object from an creates an object which is none of these
any object. object of same class pointer to copied object
81 For initializing the data members of class data members get creates an object from an creates an object which is none of these
_ _ is used. initialized automatically object of the same class. pointer to copied object
in C++
82 For initializing the data members of class _ data members get constructor destructor none of these
is used. initialized automatically
in C++
83 A class can have . all the constructors that only parameterized and only copy constructors only parameterized
are required copy constructors constructors
84 Which of the following statement is correct ?
A. constructors can have default parameters.
B. constructor cannot have default parameters.
C. constructor cannot have more than one
default parameters.
D. At the most 3 default parameters are
allowed for constructor.
ANSWER: A

85 Which constructor will execute in following constructor 1 constructor 2 constructor 3 syntax error
code?
class test{
public:
int a,b;
test(){a=b=1;}
test(int a){a=a;b=1;}
test(int a,int b){a=a;b=b;}
}

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 47


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

int main()
{
test obj(1,2);
return 0;
}

86 What value should destructor return ? status code that indicates pointer to class destructor does not return object of a class
that allocated memory for any value
object is freed.
87 Which of the following is nota type of default constructor parameterized constructor copy constructor public constructor
constructor?
88 Which of the following statement will invoke TEST T1(T2) T1=new Test(); T1=T2 none of these
copy constructor for class TEST?
89 Operator overloading is _. technique to work with technique which allows making new C++ giving new relevent
objects C++ to handle more than operators meaning to existing
one operators C++ operators
without changing
basis meaning
90 Operator function is created using _ allocator . constructor operator iterator
keyword.

91 How tp declare operator function ? operator function_name operator operator_sign() operator_sign none of these
92 Which of following operator cannot be + - :: []
overload?
93 Operator function must be _ . only 1 1 and 3 2 and 3 All 1,2 and 3
1. Non-static member function 2. Static
function 3. friend function
94 In C++ _ _ operator is used for dynamic Scope resolution operator conditional operator new arithmetic operator
memory allocation. +
95 While overloading binary operator using Zero argument one argument two arguments it depends upon the
member function it requires . operator to be
overloaded
96 What will be the output of the following 30 3 00 11 22 22 11
code?

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 48


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

vector vector::operator +(vector obj)


{
vector temp;
temp.p=p+obj.p;
temp.q=q+obj.q;
return(temp);
}
void main()
{
vector a(10,20);
vector b(1,2);
vector c,
c=a+b;
cout<<c.p<<""and<<c.q;
}
97 Reusability of code is achieved by _ _. encapsulation polymorphism inheritance none of these
98 The derived class is derived from _ _. .main base class friend class

99 Which of the following is a type of data members member function . both A and B none of these
inheritance?

100 Which of the following is a type of single inheritance and single and multiple Single ,multiple, single, multiple,
inheritance? multilevel inheritance inheritance multilevel inheritance multilevel
,hierarchical and
hybrid inheritance
]
101 In relationship an object of derived class encapsulation . polymorphism inheritance none of these
can also be treated as an object of its base
class.
102 For deriving the child class from the base :: : ; ->
class which symbol is used?
103 What will be output of following code? syntax error 55.55 10 10 55.55 55.55
Class A
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 49


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

public:
A(int n)
{
cout<<n;
}
};
class B:public A
{
B(int n,double d):A(n)
{
cout<<""<<d;
}
};
int main()
{
B b(10 ,55.55);
return 0;
}
104 What will be the output of the following 10 A 11.11 A 11.11 10 A 11.11
code?
Class A
{
public:
A(int x)
{
cout<<x;
}
};
class B: public A
{
public:
B(int x,char y):A(x)
{
cout<<" "<<y;

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 50


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

}
};
class C:public B
{
public:
C(int x,char y,double z) :B(x,y)
{
cout<<" "<<z;
}
};
int main()
{
C c(10,'A’,11.11);
return 0;
}
105 When an object of derived class is instantiated base class constructor derived class constructor not allowed to instantiate none of these
the _ is called explicitly or implicitly. derived class constructor
106 Class b is derived from class A then it is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
called____
107 Class C is derived from class B and class B is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
derived from class A then it is called .
108 Class D is derived from class Base 1 and Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Class Base 2 then it is called _ _.
109 Class A,B,ansC are derived from class Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Base2then it is called __ .
110 What will be the output of the following 100 0 syntax error none of these
code?
class A
{
private:
int x;
protected:
int y;
public:

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 51


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

int z;
};
class B:public A
{
};
int main()
{
B b;
b.x=100;
cout<<b.x;
return 0;
}
111 When base class is derived in protected mode only 1 ,5 only 2,4 only 1,6 only 2,6
then .
1. public members of base class become
private members of derived class.
2. public member of the base class become
proctected members of derived class
3. public members of base class become
public members of derived class.
4. protected members of base class become
proctected members of derived class.
5. protected members of base class become
private members of derived class.
6. protected members of base class become
public members of derived.
112 When deriving a class with public inheritance, Public, public Public, private public ,protected protected ,private
public members of the base class become
members of the derived class and protected
members of the base class become
members of the derived class.
113 If the class is derived using protected mode public members private members protected none of these
then public members of the base class become
_ of derived class.

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 52


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

114 If the class is derived using protected mode public members private members protected none of these
then protected members of the base class
become _ of derived class.
115 If the class is derived using protected mode public members private members protected none of these
then private members of the base class
become _ of derived class.
116 What will be the output of the following x=10,y=20,z=30 error for x,y=20,z=30 error for x and y,z=30 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
117 If a class is derived using private mode then public members private members protected none of these
public members of base class become _ of
derived class.

118 If a class is derived using private mode then public members private members protected none of these
protected mode members of base class
become _ _ of derived class

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 53


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

119 If a class is derived using private mode then public members private members protected none of these
private mode members of base class become
_ _ of derived class

120 What will be the output of the following x=100,y=200,z=300 error for x,y=200,z=300 error for x and y,z=300 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:private A
{
public:
void display()
{
x=100;
y=200;
z=300;
}
};
121 What will be the output of the following The value of x,y and z are error for assigment of x error for assignment of x error for accessibilty
code? assigned as 10,20,30 and y of display ()
class A respectively function
{
private:
int x;
protected:
int y;

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 54


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

public:
int z;

void display()
{
x=10;
y=20;
z=30;
}
};
class B:private A
{

};
int main()
{
B b;
b.display();return 0;
}
122 During class inheritance if the visibility mode public private protected none of these
of derivation is not specified then the default
visibility mode is _ .

123 What is the difference between protected and private member is not protected member is both are inheritable but both are inheritable
private access specifier ? inhertiable and not inheritable and also private is accessible inthe but protected is not
accessible in derived accessible in derived class derived class accessible in the
class derived class.
124 If a derived class is struct then its visibiltiy public private protected . cannot inherit
mode is _ . structure
125 The constructors for both derived and base only the constructor of only the constructor of the constructor of base the constructor of
class are defined .using the main the object off derived class will be base class will be invoked. class will be invoked and derived class will be
derived class is created . invoked then the constructor of invoked and then the
In such a situation _. derived class will be constructor of base
invoked class will be invoked

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 55


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

126 What will be the output of the following base class constructor derived class constructor base class constructor derived class
code? derived class constructor constructor base
class A class constructor
{
public:
A()
{
cout<<"base class
construtor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class
Constructor";
}
};
int main()
{
B b;
return 0;
}

127 If we define a base class constructor with optional compusory depends upon the it will generate
arguments then it is _ for derived class to compiler syntax error because
have constructor and pass argument to base paramerized
class constructor. constructor is not
allowed in base class
128 What will be the output of the following . B_constructor B_constructor B_constructor Run time error
code? D_constructor D_constructor B_destructor
Class A D_destructor B_destructor D_constructor D_

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 56


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

{ B_destructor D_constructor destructor


public:
A()
{
cout<<"B_Constructor";
}
~A()
{
cout<<"B_Destructor";
}
};
int main()
{
B b;
return 0;
}

129 Which of the following is/are valid ways . int *p = new int(100); int *p; p = new int; *p = int *p = NULL; p = All of these
to allocate memory for an integer by 100; new int; *p=100;
dynamic memory allocation in CPP?
130 During dynamic memory allocation in False NULL Zero None of these
CPP, new operator returns _
value if memory allocation is
unsuccessful.
131 When the memory spaces for the member when the objects are when the class are when member All of these
functions are allocated? created created functions are defined as
a part of class
132 Why separate memory locations are member variables hold each object in the class Both a,b none of these
essential for an object different data values for has separate member
different objects function

133 The amount of memory allocated for an amount of memory amount of memory amount of memory amount of memory
object is equal to required by member required by data required by both data required by the

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 57


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

functions of that class members of that class members and data class
functions
134 All the objects of a class share the same data members member functions both data members and None of these
copy of member function
135 How will you free the memory allocated delete(p) delete p delete(int p) delete (p,0)
by the following program?
#include <iostream>
using namespace std
int main()
{
int *p;
p=new int;
return 0;
}
136 When the memory spaces for the data when the class is when the object of the when the member None of these
member are allocated? specified class is declared function is declared
137 How much memory will be allocated to 8Bytes 7Bytes 6Bytes No memory will
the object obj1 of the following class? be allocated
class test
{
float a;
int b;
char c;
}
int main()
{
test obj1;
return 0;
}

138 What are arrays in the C++? . A series of elements A series of elements of A series of elements of A series of

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 58


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

of same type placed in different type placed in same type placed in elements of
continuous block of continuous block of non-continuous block different type
memory. memory of memory placed in non-
continuous block
of memory.
139 The memory address for array can be a[0] address_of(a) a[1] a
obtained using _ _.
140 Which of the following are characteristics The array contains all All the elements of the The name of the array All of the above
of array? the elements of same array share the same represents the address
data type name and then can be of the first element of
distinguished from one an array
another by index
141 How will you pass the large objects in using call by value using call by reference either a or b none of these
C++? method method
142 Which of the following correctly declares int array[10]; int array; array{10}; array array[10];
an array?
143 What is the index number of the last 9 8 0 Programmer-
element of an array with 9 elements? defined
144 The process of storing the elements in an initialization of array declaration of array finalization of array none of the above
array is called as
145 Which of the following correctly declares ABC array[10]; ABC array; array{10}; array array[10];
an array of objects for a class ABC?
146 How much memory will be allocated to 10Bytes 20Bytes 40Bytes No memory is
the object obj1 in the following code? allocated
#include<iostream>
using namespace std;
class student
{
int age;
int roll_no;
public:

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 59


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

………
....……
};
int main()
{
student s[10];
………..
………..
return 0;
}
147 What will be the output of the following 30and3 0and0 11and 22 22and11
code?
vector vector::operator+(vector obj)
{
vector temp;
temp.p=p+obj.p;
temp.q=q+obj.q;
return (temp);
}
int main()
{
vector a(10,20);
vector b(1,2);
vector c;
c=a+b;
cout<<c.p<<”and”<<c.q;
return 0;
}
148 Which of the following statements are only 1 and 2 only 3 and 4 All of the above None of the above
true for operator overloading?
1. Only existing operators can be

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 60


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

overloaded
2. The overloaded operator must have at
least one operand that is of user defined
type.
3. Overloaded operators follow the syntax
rules of the original operators.
4. Binary arithmetic operators such as +,-
,* and / must explicitly return a value.

149 Which is the correct function prototype complex complex complex complex
declaration for overloading the ‘+’ operator+(complex); operator++(complex); operator+(complex) operator(complex);
operator in class ‘complex’?
150 Inheritance is ............... in nature. Intransitive Transitive Both (a) & (b) None of the above

151 The result of the following statement is ans=7, y=7 ans=8,y=7 ans=8,y=8; none of the above
int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;
152 What is the output of the following code? Error The result of addition The result of addition The result of
#include<iostream> is:16 is:sum(); addition is:
using namespace std;
class test
{
int a,b;
public:
test(int x, int y)
{
a=x; b=y;
}
int sum();

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 61


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

void display();
};
int test::sum()
{
return a+b;
}
void test::display()
{
cout<<”\nThe result of addition
is:”<<sum();
}
void main()
{
test obj1(7,9);
obj1.display();
return 0;
}
153 A constructor function is ___ A friend function to a A member function with A non-member None of the above
class the same name as its function
class
154 A constructor function is generally In the public section of In the private section of In the protected section None of the above
defined __ a class a class of a class
155 A class having no public constructors is A private class A public class An abstract class None of the above
__
156 If a constructor function is defined in The object cannot be Only member functions Both (a) & (b) None of the above
private section of a class, then created and friends may declare
__ objects of the class
157 A constructor with no argument is Default constructor Parameterized Copy constructor None of the above
__ _ constructor

158 If arguments are provided to a constructor Default constructor Copy instructor Parameterized None of the above

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 62


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

function, then it becomes constructor


__

159 The parameterized constructor Needs initial values as Can be invoked Can be invoked None of the above
__ arguments during explicitly only implicitly only
creation of an object
160 Given a class named Book, which of the Book ( ) { } Book ( Book b) { } Book ( Book &b) { } Book (char*
following is not a valid constructor? author, char* title)
{}
161 Which of the following statements A constructor may be Constructor can have Member functions may None of the above
regarding constructor is false? defined static default arguments be invoked from within
a constructor
162 A destruction function Takes no argument and Has name similar to that Is used to destruct an All of the above
has no return type not of class, preceded by object, constructed
even void tilde(~) symbol through constructor
function
163 Destructors are called __ _ in the same order of in the reverse order of in any random order none of the above
constructor calls constructor calls

164 Constructors are used _ to build a user interface deallocate memory initialize newly created to construct
objects functions
165 If a default constructor is not defined then it will cause syntax ) it will cause runtime the complier will create none of these
__ . error error constructor for creating
an object
166 How many constructors can a class have? 0 1 2 any number
167 Which of the following is not the They should be They do not have return They can not be They can be
characteristic of constructor. declared in the public type. inherited virtual.
section.
168 In which case is it mandatory to provide a Almost in every class Class for which two or Class for which copy Class whose
destructor in a class? more than two objects constructor is defined objects will be
will be created created

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 63


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

dynamically
169 Class function which is called Constructor Destructor Friend function Inline function.
automatically as soon as the object is
created is called as __
170 Complement of the constructor is Overloading Inheritance Polymorphism Destructor
171 If c1 and c2 are objects of class complex Sum is : 12+i2 Sum is : 5+i4 Sum is : 7-i2 syntax error
and c1=5+i4 and c2=7-i2 then what is the
output of the following program?
#include <iostream>
#include <math.h>
using namespace std;

class complex
{
int real,img;
public:

void display()
{
if(img>0)

cout<<real<<"+i"<<img<<endl;
else
{
cout<<real<<"-i"<<-
img<<endl;
}
}
complex operator+(complex);
};
complex complex :: operator+(complex c2)
{
complex sum;

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 64


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

sum.real = real+c2.real;
sum.img = img+c2.img;
return (sum);
}
int main()
{
complex c1,c2,ans;
ans = c1+c2;
cout<<"Sum is : ";
ans.display();
return 0;
}
172 An array name is a _____ Subscript formal parameter memory address prototype

173 If an array is declared as 3, 2 0, 2 3, 0 0, 4


int a[4] = {3, 0, 1, 2}, then values
assigned to a[0] & a[4] will be ___ _

174 Declaration of a pointer reserves memory for the object for the pointer both for the object and None of these.
space the pointer
175 Identify the operator that is NOT used -> & * >>
with pointers
176 An array element is accessed using a FIFO approach an index number the operator member name
177 The address of a variable temp of type *temp &temp float& temp float temp&
float is
178 Identify the correct sentence we cannot create the we can create the Array we can use reference to none of the
regarding inequality between reference array of reference. of reference reference mentioned
and pointer.
179 Functions can return_ _ Arrays References Objects All of above

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 65


Subject: Object Oriented Programming Using CPP

Question bank for online exam

Classes and Objects:

1. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function

2.Classes are useful because they


[A] are removed from memory when not in use
[B] permit data to be hidden from other classes
[C] bring together all aspects of an entity in one place
[D] can closely model objects in the real world

3. Which member function of class cannot modify its objects attributes ?


[A] friend functions
[B] Private member functions
[C] Constant member functions
[D] Static member functions

4. Which of the following is an abstract data type?


A. int
B. double
C. string
D. Class

5. Which of the following is correct about class and structure?


A. class can have member functions while structure cannot.
B. class data members are public by default while that of structure are private.
C. Pointer to structure or classes cannot be declared.
D. class data members are private by default while that of structure are public by default.

6. Which of the following statement is correct?


A. Class is an instance of object.
B. Object is an instance of a class.
C. Class is an instance of data type.
D. Object is an instance of data type.

7. What does your class can hold?


A) Data
B) Functions
C) Both A & B
D) None of the above

8. How many specifiers are present as access specifiers in a class in C++?


A) 1
B) 2
C) 3
D) 4

9. Whichoperator is used to define the member of a class externally?


A) :
B) ::
C) #
D) None Of The Mentioned

10. Which of the following is a valid class declaration?


A) class A { int x; };
B) class B { }
C) public class A { }
D) object A { int x; };

11. The fields in the class in c++ program are by default


A) protected
B) private
C) public
D) none of the mentioned

12. What is class in c++ ?


A. When you define a class, you define a blueprint for a data type.
B. When you define a class, you add more functionality.
C. When you define a class, you define the logic.
D. When you define a class, you make debugging.

13. What is object in C++ ?


A. Object is part of syntax of a class.
B. Object is datatype of a class.
C. Object is an instance of a class.
D. Object is function of a class.

14. ‘cin’ is __
A –a Class
B - an Object
C –a Package
D – Namespace
15. With respect to streams >> (operator) is called as __________
A - Insertion operator
B - Extraction operator
C - Right shift operator
D - Left shift operator

16. In C++, by default all members are ........ in a struct and ........ in a class .
A - public , private
B - public , public
C - private , public
D - private , private

17. With respect to streams << (operator) is called as __________


A - Insertion operator
B - Extraction operator
C - Right shift operator
D - Left shift operator

18. Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?
A-A class member and a class object.
B-A class object and a class.
C-A class and a member of that class.
D-A class object and a member of that class.

19. Which of the following keywords is used to control access to a class member?
A-Default
B-Break
C-Protected
D-Asm

20. 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.

21. Which of the following statements is correct?


A-Data items in a class must be private.
B-Both data and functions can be either private or public.
C-Member functions of a class must be private.
D-Constructor of a class cannot be private.

22. In C++, a function contained within the class is called ?


A- member function
B- a class function
C- a method
D- none of above

23. What is the output of following program ?


#include<iostream>
using namespace std;
inti=10;
int main ( )
{
inti=20;
{
inti=30.;
cout<<i<< :: i ;
}
return 0;
}
A- 3010
B- 3020
C- will result in a run time error
D. none of the above

24. What is the output of the following program?


#include<iostream>
using namespace std;
class abc {

public:
inti;

abc(inti) {
i = i;
}
};

main() {
abc m(5);
cout<<m.i;
return 0;
}
A-5
B - Garbage
C - Error at the statement i=i;
D - Compile error: ‘i’ declared twice.

25. What is the output of the following program?


#include<iostream>
using namespace std;
void swap(int m, int n) {
int x = m;

m = n;
n = x;
}
main() {
int x = 5, y = 3;
swap(x,y);
cout<<x<<" "<<y;
return 0;
}

A-35
B-53
C-55
D - Compile error

26._________ is a special character used to mark end of class.


A- :
B- ;
C-#
D-$

27. How much memory will be allocated to object obj1 in following code?
#include<iostream>
using namespace std;
Class ABC
{
int x;
char y;
public:
void getdata();
};
main()
{
ABC obj1;

}
A-1 Byte
B-2Bytes
C-3 Bytes
D- 4 Bytes

28. What is the output of the following program?


#include<iostream>
using namespace std;
class Abc
{
intx=2;
int y=3;
void display()
{
cout<<x<<" "<<y;
}
};
int main()
{
Abcobj;
obj.display();
return 0;
}
A-Error
B-2 3
C-3 2
D-x y

29. Everything defined at the program scope level (ie. outside functions and classes) is said to be _______
A) local scope
B) regional scope
C) global scope
D) static scope

30. A property which is not true for classes is that they


(A) are removed from memory when not in use.
(B) permit data to be hidden from other classes.
(C) bring together all aspects of an entity in one place.
(D) Can closely model objects in the real world.

31. Which of the following is false for cin?


(A) It represents standard input.
(B) It is an object of istream class.
(C) It is a class of which stream is an object.
(D) Using cin the data can be read from user’s terminal.

32. An expression A.B in C++ means ____


A) A is member of object B
B) B is member of Object A
C) Product of A and B
D) None of these

33. A template class


(A) is designed to be stored in different containers
(B) works with different data types
(C) generates objects which must be identical
(D) generates classes with different numbers of member functions.

34. What is the output of the following program?


#include <iostream>
using namespace std;
int main()
{
inti;
for (i = 0; i< 10; i++);
{
cout<<i;
}
return 0;
}
a) 0123456789
b) 10
c) 012345678910
d) compile time error

35. What is the output of the following program?


#include <iostream>
using namespace std;
int main()
{
int n = 15;
for ( ; ;)
cout<< n;
return 0;
}
a) error
b) 15
c) infinite times of printing n
d) No output
36. What is the output of following program?
#include <iostream>
using namespace std;
class rect
{
int x, y;
public:
void val (int, int);
int area ()
{
return (x * y);
}
};
void rect::val (int a, int b)
{
x = a;
y = b;
}
int main ()
{
rectrect;
rect.val (3, 4);
cout<< "rect area: " <<rect.area();
return 0;
}
a) Error
b) rect area: 12
c) rect area:24
d) none of the mentioned

37. What is the output of the following program?


#include <iostream>
using namespace std;
class Box
{
public :
double length;
double breadth;
double height;
};
int main( )
{
Box Box1;
double volume;
Box1.height = 5;
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout<< "Volume of Box1 : " << volume <<endl;
return 0;
}
a) "Volume of Box1 : " 213
b) Volume of Box1 : 213
c) Volume of Box1 : 215
d) Volume of Box1 : 217

38. What is the output of following program?


#include <iostream>
using namespace std;
class sample
{
private:
intvar;
public:
void input()
{
cout<<”Enter an integer:”;
cin>>var;
}
void output()
{
cout<< "Variable entered is ";
cout<<var<< "\n";
}
};
int main()
{
sample object;
object.input();
object.output();
object.var();
return 0;
}
a) Enter an integer 5
Variable entered is 5
b) var
c) error
d) none of the mentioned

39. What is the output of following program?


#include <iostream>
using namespace std;
class number
{
inti;
public:
intgeti();
void puti(int j);
};
int number::geti()
{
return i;
}
void number::puti(int j)
{
i = j;
}
int main()
{
number s;
s.puti(10);
cout<<s.geti( );
return 0;
}
a) 10
b) 11
c) 20
d) 22
40. If different objects are created the separate memory space is created for ____.
A. data members
B. member functions
C. both A ans B
D. none of these

41. The memory required by any objects is dependent upon following factors
A. size of non static data members of the class
B. order of data members
C. Byte padding
D. all of these

42. Which of the following is correct way of declaring object of a class ?


A. Class_nameobject_name;
B. object_nameclass_name
C. class class_nameobject_name
D. class class_name object object_name

43. What is the output of the following code?


#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
count++;
}
void display()
{
cout<count;
}
};
int main()
{
test obj;
obj.display();
return 0;
}
A. 0
B. 1
C. garbage value
D. syntax error

44. What is the output of the following program?


#include <iostream>
using namespace std;
class integer
{
int a;
public:
void geta()
{
cout<<"Enter data"<<endl;
cin>>a;
}
void seta(int x=0)
{
x=a;
}
void disp()
{
cout<<"Data is "<<a<<endl;
}
};
int main()
{
integer I1;
I1.geta();
I1.disp();
return 0;
}
a.Enter data
5
Data is 5
b. Enter data
5
Data is a
c.Enter data
5
Data is0
d. Syntax Error

45.The constructors and destructors for objects are automatically invoked ____.
A. by making explicit call to constructor and destructor functions
B. when object enters and leaves its scope.
C. when inheritance occurs
D. none of these
Multiple choice question bank on topic defining member functions, making outside
function inline, nesting of member functions, private member functions

1. Member function can be defined


a ) Outside the class definition
b) Inside the class definition
c) Both a & b
d) None of these

2. Member function defined inside the class are automatically


a) Linein functions
b) Inline functions
c) Member functions
d) Private functions

3. Member functions of a class can be called


a ) Only by object of that class
b) Only by object of other class
c) By an object of any class
d) all of the above

4. A member function can be called by using its name inside another member function of
the same class is called as
a) Inline function
b) Member function
c) Nesting of member function
d) Public member function

5. Member function can be


a) Only private
b) Only public
c) Only protected
d) Any of the above

6. A private member function can only be called by another function


a) that is a member of its class
b) that is a member of another class
c) that is a member of any class
d) by the object of that class

7. Choose the correct statement


a) Only data members are private
b) Only member functions are public
c) Both data & member functions can be public
d) The member functions are private

8. What is the output of following code

#include <iostream>
using namespace std;

classabc
{
private:
int array1[5]={0,2,4,8,5};
public:
void compute();
};

voidabc ::compute()
{
int result=0;
for(inti=0;i<5;i++)
{
result=result+array1[i];
}
cout<< result;
}
int main()
{
abc x;
x.compute();
return 0;
}
a) 19
b) 20
c) Garbage value
d) Syntax error

9. Inline functions are


a) declared in the class defined outside the class
b) defined outside the class using keyword inline
c) defined inside the class using keyword inline
d) none of the above
10. Member functions are enclosed within
a) class
b) structure
c) union
d) None of the above

11. The default class access scope is


a) Private
b) Public
c) Protected
d) None of the above

12. The private data members of a class are accessible


a) directly to objects of that class
b) only to the member functions of that class
c) to any function defined outside a class
d) none of the above

13. The objects can directly access


a) Public members
b) Private members
c) Both (a) & (b)
d) None of the above

14. 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

15. A function defined inside a class is called

a)A class function


b) A friend function
c) A member function
d) None of the above

16. The memory for member functions is allocated


a) When a class is defined
b) when a object is created
c) When an object is initialized
d) None of the above

17. State true of false.


i) We cannot make the function inline by defining a function outside the class.
ii) A member function can be called by using its name inside another member function of
the same class, this is known as nesting of member function.
a) True, True
b) True, False
c) False, True
d) False, False

18. Which of the following keywords are used to control access to a class member?
a) default
b) break
c) protected
d) goto

19. If function is defined outside the class, its prototype declaration must be
a ) inside class
b) outside class
c) botha&b
d) None of the above

20. What is the output of following code

#include <iostream>
using namespace std;
class A
{
int c;
void add (int a, int b)
{
c=a+b;
cout<<"c="<<c;
}
};
int main()
{
A a;
a.add(5,7);
return 0;
}
a) 12
b) Error
c) 18
d) None of the above

21. What is the output of the following program?

#include <iostream>
using namespace std;
class B
{
public:
void main()
{
cout<<endl<<"In member function main()";
}
};
int main()
{
B b;
b.main();
return 0;
}

a) In member function main()


b) Syntax error
c) Garbage value
d) a & b both

22. which of the following is true while defining member function outside the class
1) return_typeclass_name :: member_function() {}
2)class_name ::return_typemember_function() {}
a) 1 true
b) 2 true
c) 1 & 2 both are true
d) both are false

24. Which can be passed as an argument to a function?


(A) constant
(B) expression
(C) another function
(D) all of the above.

25. What is true about inline functions ?


[A] It's a compulsion on the compiler to make function inline
[B] It's a request to the compiler to make te function inline
[C] It's the indication to the compiler that the function is recursive
[D] It's the indication to the compiler that the function is member function

26. Which of the following parameter passing mechanism is/are supported by C++ but not in C?
[A] Pass by value
[B] Pass by reference
[C] Pass by value result
[D] All of the above

27. Which of the following type of function is an ideal candidate for being declared inline ?
[A] A function that is small and is not called frequently
[B] A function that is small and is called frequently
[C] A function that is not small and is not called frequently
[D] A function that is not small and is called frequently

28. When an argument is passed by reference


[A] a variable is created in function to hold the argument value
[B] the function cannot access the argument value
[C] a temporary variable is created in the calling program to hold arguments value
[D] None of these

29. A class cannot be ____________.


A. virtual
B. friend
C. generic
D. Inline

30. Which of the following is a valid inline function ‘myfun’?


A. inline voidmyfun {//function code}
B. void myfun() inline {//function code}
C. inline::void myfun{//function code}
D. none of these

31. A variable is defined within a block in a body of a function. Which of the following are true
?a. It is visible from the point of definition to the end of the program.
b. It is visible throughout the function.
c. It is visible from the point of definition to the end of the block.
d. It is visible throughout the block.

32. Following is the main benefit of inline function/


a. It decreases the size of the program
b. It simplifies the source code
c. It increases the speed of resulting program
d. It removes unnecessary functions

33. Following is the limit on inline function


a. Inline function cannot return a value
b. Inline function has to return a value
c. Inline function must have less than 10 lines of code
d. The compiler can choose to ignore an inline directive

34. When will you make a function inline?


a. If that function is small and is not called frequently
b. If that function is small but called frequently
c. If that function is not small but called frequently
d. If that function is not small and not called frequently

35. What is the purpose of the keyword inline?


a. It allows one line function declaration
b. It causes the replacement of function calls by the code from the function
c. It indicates function declaration
d. It tells compiler to use that function in the same source code file

36. What is the output of the following code?


#include<iostream>
using namespace std;
class test
{
inta,b;
public:
test(int x, int y)
{
a=x; b=y;
}
int sum();
void display();
};
int test::sum()
{
returna+b;
}
void test::display()
{
cout<<”\nThe result of addition is:”<<sum();
}
void main()
{
test obj1(7,9);
obj1.display();
return 0;
}
a. Error
b. The result of addition is:16
c. The result of addition is:sum();
d. The result of addition is:

Constructor and Destructor

1) A constructor function is ___________


a) A friend function to a class
b) A member function with the same name as its class
c) A non-member function
d) None of the above

2) A constructor function is generally defined ________________


a) In the public section of a class
b) In the private section of a class
c) In the protected section of a class
d) None of the above

3) A class having no public constructors is ____________


a) A private class
b) A public class
c) An abstract class
d) None of the above

4) If a constructor function is defined in private section of a class, then ________________


a) The object cannot be created
b) Only member functions and friends may declare objects of the class
c) Both (a) & (b)
d) None of the above

5) A constructor with no argument is _____________


a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) None of the above

6) If arguments are provided to a constructor function, then it becomes ______________


a) Default constructor
b) Copy instructor
c) Parameterized constructor
d) None of the above

7) The parameterized constructor __________________


a) Needs initial values as arguments during creation of an object
b) Can be invoked explicitly only
c) Can be invoked implicitly only
d) None of the above

8) Given a class named Book, which of the following is not a valid constructor?
(A) Book ( ) { }
(B) Book ( Book b) { }
(C) Book ( Book&b) { }
(D) Book (char* author, char* title) { }

9) Which of the following statements regarding constructor is false?


a) A constructor may be defined static
b) Constructor can have default arguments
c) Member functions may be invoked from within a constructor
d) None of the above

10) A destruction function ____________


a) Takes no argument and has no return type not even void
b) Has name similar to that of class, preceded by tilde(~) symbol
c) Is used to destruct an object, constructed through constructor function
d) All of the above

11) Destructors are called _______________


a) in the same order of constructor calls
b) in the reverse order of constructor calls
c) in any random order
d) none of the above

12) Constructors are used ___________

a) to build a user interface


b) deallocate memory
c) initialize newly created objects
d) to construct functions

13) What is the output of the following code?


#include <iostream>
using namespace std;

class test
{
private:
int a;
public:
test()
{
a=0;
cout<<"constructor";
}
~test()
{
cout<<"destructor";
}
};
int main()
{
test a[2];
return 0;
}
a) constructorconstructordestructordestructor
b) constructordestructor
c) constructorconstructor
d) no output

14) What is the output of the following code?


#include <iostream>
using namespace std;

class test
{
public:
test()
{cout<< "constructor";}
~test()
{cout<< "destructor";}

};
int main()
{
delete new test();
return 0;
}
a) syntax error
b) nothing will be displayed
c) constructor destructor
d) constructorconstructor

15) If a default constructor is not defined then __________.


a) it will cause syntax error
b) it will cause runtime error
c) the complier will create constructor for creating an object
d) none of these

16. How many constructors can a class have?


(A) 0
(B) 1
(C) 2
(D) any number

17. Which of the following is not the characteristic of constructor.


(A) They should be declared in the public section.
(B) They do not have return type.
(C) They can not be inherited.
(D) They can be virtual.

18. 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

19. Class function which is called automatically as soon as the object is created is called as __
A - Constructor
B - Destructor
C - Friend function
D - Inline function.

20. Complement of the constructor is


A - Overloading
B - Inheritance
C - Polymorphism
D – Destructor

21. The destructor has the same name as the constructor, but is preceded by a
A - '~'
B - '-'
C - '^'
D - '::'

22. A Constructor that does not have any parameters is called____________ Constructor.
a. Custom
b. Dynamic
c. Static
d. Default

23.Which of the followings are true about constructors?


1. A class can have more than one constructor.
2. They can be inherited.
3. Their address can be referred.
4. Constructors cannot be declared in protected section of the class.
5. Constructors cannot return values.

a. Only 1,2,4
b. 1,2,4,5
c. 1,3,5
d. 1,4,5

24.If default constructor is not defined, then how the objects of the class will be created?
a. The compiler will generate error
b. Error will occur at run-time.
c. Compiler provides its default constructor to build the object.
d. None of these

25.A Constructor is called whenever


a. an object is declared
b. an object is used
c. a class is declared
d. a class is used

26. A destructor takes


a. one argument
b. two arguments
c. three arguments
d. zero argument

27. What value should return a destructor?


a) A pointer to the class
b) An object of the class
c) A status code indicating whether the class is destroyed properly
d) Destructors do not return a value

28. What will be the output of the following program?


#include<iostream>
using namespace std;
class Rectangle
{
int length, width;
public:
Rectangle (int x, int y)
{
length = x;
width = y;
}
intRectArea ()
{
return (length *width);
}
};
int main()
{
Rectangle rect1(10,20);
int area1 = rect1.RectArea();
cout<<"Area1="<<area1;
return 0;
}
a. Area1= 200;
b area1= 200;
c. Area1=area1
d. No output

29. If ‘Student’ is the name of the class, then which of the following constructor declaration in
class is correct?
a. Student(){}
b. Student(){};
c. Student::Student(){};
d. none of the above

30. A class is not having default constructor but o ne parameterized constructor. We have created
an object that needs zero argument constructor. What will happen in this case?
a. The desired object will get created because compiler will create an implicit default constructor
b. It will cause syntax error
c. It will cause runtime error
d. None of these

31. Which constructor will be executed in the following code?


#include<iostream>
using namespace std;
class test
{
public:
inta,b;
test(){a=b=1;} //constructor 1
test(int a) {a=a;b=1;} // constructor 2
test(int a , int b){a=a; b=b;} //constructor 3
};
int main()
{
testobj(1,2);
return 0;
}
a. constructor 1
b. constructor 2
c. constructor 3
d. Syntax error

32. What is the output of the following program?


#include<iostream>
using namespace std;
class test
{
private:
int a
public:
test(int x);
void display();
};
test::test(inti)
{
a=i;
}
void test::display()
{
cout<<” ”<<a;
}
int main()
{
testobj[3];
obj[0].display();
obj[1].display();
obj[2].display();
return 0;
}
a. 0 1 2
b. 0 0 0
c. three garbage values
d. syntax error

Operator Overloading

1. While overloading binary operators using member function, it requires ___ argument/s.

a. Zero
b. One
c. Two
d. Three

2. In case of binary operator overloading with member function, which of following statement
should be taken into consideration?
A. Right hand operand must be object.
B. Left hand operand must be object.
C. Both the operands must be objects.
D. All of these should be considered.

3) Scope resolution operator is used______ .

a. to resolve the scope of global variables only


b. to resolve the scope of functions of the classes only
c. to resolve scope of global variables as well as functions of the classes
d. None of these

4) ___________ header file is used for manipulators.

a. <iomanipulator.h>
b. <stdiomanip.h>
c. <stdmanip.h>
d. <iomanip.h>

5) An operator function is created using _____________ keyword.

a. iterator
b. allocator
c. constructor
d. operator

6) Operator overloading is
a. technique to work with objects
b. technique which allows C++ to handle more than one operator
c. making new C++ operators
d. giving new relevant meaning to existing c++ operators without changing basic meaning

7) Which of the following is the perfect set of operators that can’t be overloaded in CPP ?

a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()
c. :: , . , .* , ?:
d. :: , ->, * , new, delete
8) new operator is used
a) to define a new variable
b) to create a new data type
c) to allocate memory dynamically
d) none of the above

9) Which of the following statements can be overloaded?


a) Size of operator
b) Scope resolution operator (::)
c) Class member access operator (->)
d) Pointer to member operator

10) While overloading, a unary operator


a) Takes no arguments
b) Takes one argument
c) Takes two arguments
d) None of the above

11. Which of the following statements is NOT valid about operator overloading?
(A) Only existing operators can be overloaded.
(B) Overloaded operator must have at least one operand of its class type.
(C) The overloaded operators follow the syntax rules of the original operator.
(D) none of the above.

12) When an arithmetic assignment operator is overloaded, the result


a) goes in the object to the left of the operator
b) goes in the object to the right of the operator
c) goes in the object of which the operator is a member
d) none of the above

13) The function that overloads as operator, precedes with the keyword
a) function
b) operator
c) virtual
d) static

14) The operator function


a) is declared in the public section of the class
b) may be declared in the private section of the class
c) both (a) & (b)
d) none of the above
15) The operator functions may be invoked
a) implicitly
b) explicitly
c) both (a) & (b)
d) none of the above

16. Operator overloading is ?


a. giving new meaning to existing c++ operators
b. making c++ operators work with objects
c. giving c++ operators more than they can handle
d. making new c++ operators

17. When using binary operators overloaded through a member function, the left hand operand
must be__________ of the relevant class.
a. data member
b. an object
c. a variable of the member function
d. none of the above.

18. Which of the following statements are true for operator overloading?
1. Only existing operators can be overloaded
2. The overloaded operator must have at least one operand that is of user defined type.
3. Overloaded operators follow the syntax rules of the original operators.
4. Binary arithmetic operators such as +,-,* and / must explicitly return a value.
a. only 1 and 2
b. only 3 and 4
c. All of the above
d. None of the above

19. Which is the correct function prototype declaration for overloading the ‘+’ operator in class
‘complex’?

a. complex operator+(complex);
b. complex operator++(complex);
c.complex operator+(complex)
d.complex operator(complex);

20. If c1 and c2 are objects of class complex and c1=5+i4 and c2=7-i2 then what is the output of
the following program?
#include <iostream>
#include <math.h>
using namespace std;

class complex
{
intreal,img;
public:

void display()
{
if(img>0)
cout<<real<<"+i"<<img<<endl;
else
{
cout<<real<<"-i"<<-img<<endl;
}
}
complex operator+(complex);
};
complexcomplex :: operator+(complex c2)
{
complex sum;
sum.real = real+c2.real;
sum.img = img+c2.img;
return (sum);
}
int main()
{
complex c1,c2,ans;
ans = c1+c2;
cout<<"Sum is : ";
ans.display();
return 0;
}
a. Sum is :12+i2
b. Sum is :5+i4
c. Sum is :7-i2
d. syntax error

21. How to declare operator function?


a. operator function_name
b. operatoroperator_sign()
c. operator_sign
d. none of these

22. What will be the output of the following code?


vector vector::operator+(vector obj)
{
vector temp;
temp.p=p+obj.p;
temp.q=q+obj.q;
return (temp);
}
int main()
{
vector a(10,20);
vector b(1,2);
vector c;
c=a+b;
cout<<c.p<<”and”<<c.q;
return 0;
}
a. 30and3
b. 0and0
c.11and 22
d.22and11

Inheritance

1) Which of the following feature supports reusability and extensibility of classes?

a) Inheritance
b) Overloading
c) Polymorphism
d) None of the above

2) Inheritance is ………..in nature.


a) Intransitive
b) Transitive
c) Both (a) & (b)
d) None of the above

3) The result of the following statement is


inty = 7;
intans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;

a) ans=7, y=7
b) ans=8,y=7
c) ans=8,y=8;
d) none of the above

4) The process of deriving a class from another derived class is


a) single inheritance
b) multilevel inheritance
c) multiple inheritance
d) none of the above
5) When a derived class inherits only from one class and is not further inherited is
a) single inheritance
b) multiple inheritance
c) multilevel inheritance
d) hybrid inheritance

6) When a derived class inherits from many base classes it is


a) multilevel inheritance
b) single inheritance
c) multiple inheritance
d) none of the above

7) The default visibility mode while inheriting is


a) private
b) public
c) protected
d) none of the above

8) The class intended to be a base class should use visibility mode as


a) public
b) protected
c) private
d) Both (a) & (b)

9) Inheritance is referred to as
a) “is a” relationship
b) “has a” relationship
c) Both (a) & (b)
d) none of the above

10) What is meant by multiple inheritance?


a) Deriving a base class from derived class
b) Deriving a derived class from base class
c) Deriving a derived class from more than one base class
d) None of the mentioned

11) If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
(A) protected and public data only in C and B.
(B) protected and public data only in C.
(C) private data in A and B.
(D) protected data in A and B.

12) What does inheritance allows you to do?


A. create a class
B. create a hierarchy of classes
C. access methods
D. None of the mentioned

13) What is the output of following program?


#include <iostream>
using namespace std;
class student
{
public:
intrno , m1 , m2 ;
void get()
{
rno = 15, m1 = 10, m2 = 10;
}
};
class sports
{
public:
intsm;
voidgetsm()
{
sm = 10;
}
};
classstatement:publicstudent,public sports
{
inttot,avg;
public:
void display()
{
tot = (m1 + m2 + sm);
avg = tot / 3;
cout<< tot;
cout<<avg;
}
};
int main()
{
statementobj;
obj.get();
obj.getsm();
obj.display();
return 0;
}

a) 3100
b) 3010
c) 2010
d) 1010

14. What is the syntax of inheritance of class?


A. class name
B. class name : access specifer
C. class name : access specifer class name
D. None of the mentioned

15. The process of building new classes from existing one is called
(A) Structure.
(B) Inheritance.
(C) Polymorphism.
(D) Template.
16. Consider the following class definitions:
class a
{
};
class b: protected a
{
};
What happens when we try to compile this class?
(A) Will not compile because class body of a is not defined.
(B) Will not compile because class body of b is not defined.
(C) Will not compile because class a is not public inherited.
(D) Will compile successfully.

17. The major goal of inheritance in C++ is ?


a.To facilitate the reusability of code
b. To help modular programming
c. To facilitate the conversion of data types
d. To extend the capabilities of a class

18. How many types of inheritance are there in c++?


A. 2
B. 3
C. 4
D. 5

19. In case of inheritance where both base and derived class are having constructors, when an object of
derived class is created then___________
A. constructor of derived class will be invoked first
B. constructor of base class will be invoked first
C. constructor of derived class will be executed first followed by base class
D. constructor of base class will be executed first followed by derived class

20. What is the difference between protected and private access specifiers in inheritance?
A. private member is not inheritable and not accessible in derived class.
B. protected member is inheritable and also accessible in derived class.
C. Both are inheritable but private is accessible in the derived class.
D. Both are inheritable but protected is not accessible in the derived class.

21. When a base class is privately inherited by the derived class, then_____________ .
A. protected members of the base class become private members of derived class
B. public members of the base class become private members of derived class
C. both a and b
D. only b

22. The derivation of Child class from Base class is indicated by ____ symbol.
A. ::
B. :
C. ;
D. |

23.During a class inheritance in CPP, if the visibility mode or mode of derivation is not
provided, then by default visibility mode is ___________.
A. public
B. protected
C. private
D. Friend

24.What will be output of following code?


#include <iostream>
using namespace std;
class A
{
public:
A(int n)
{
cout<<n;
}
};
class B:public A
{
public:
B(intn,double d):A(n)
{
cout<<""<<d;
}
};
int main()
{
B b(10, 55.55);
return 0;
}
A. syntax error
B. 55.55 10
C. 1055.55
D. 55.55

25.What will be the output of the following code?


#include <iostream>
using namespace std;
class A
{
public:
A(int x)
{
cout<<x;
}
};
class B: public A
{
public:
B(intx,char y):A(x)
{
cout<<""<<y;
}
};
class C:public B
{
public:
C(intx,chary,double z) :B(x,y)
{
cout<<""<<z;
}
};
int main()
{
C c(10,'A',11.11);
return 0;
}
A. 10 A 11.11
B. 11.11
C. A 11.11
D. 10A11.11

26. Class B is derived from class A then it is called____


A. single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

27. Class C is derived from class B and class B is derived from class A then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

28. Class D is derived from class Base1 and class Base2 then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

29. Class B and C are derived from class A and class D is derived from class B and C, then it is
called _____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

30. What will be the output of the following code?


#include <iostream>
using namespace std;
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:public A
{
};
int main()
{
B b;
b.x=100;
cout<<b.x;
return 0;
}
A. 100
B. 0
C. syntax error
D. none of these

31. When base class is derived in protected mode then ____.


1. public members of base class become private members of derived class.
2. public member of the base class become protected members of derived class
3. public members of base class become public members of derived class.
4. protected members of base class become protected members of derived class.
5. protected members of base class become private members of derived class.
6. protected members of base class become public members of derived.
A. only 1 ,5
B. only 2,4
C. only 1,6
D. only 2,6

32. When deriving a class with public inheritance,public members of the base class become____
members of the derived class and protectedmembers of the base class ___ become members of
the derived class.
A. public public
B. public private
C. public protected
D. protected private

33. If the class is derived using protected mode then public members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. none of these

34. If the class is derived using protected mode then protected members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. none of these

35. If the class is derived using protected mode then private members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. no access

36. What will be the output of the following code?


#include <iostream>
using namespace std;

class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
A. x=10,y=20,z=30
B. error for x,y=20,z=30
C. error for x and y,z=30
D. error for x,y and z

37. If a class is derived using private mode then public members of base class become ___ of
derived class.
A. public members
B. private members
C. protected
D. none of these

38. If a class is derived using private mode then protected mode members of base class become
____ of derived class
A. public members
B. private members
C. protected
D. none of these
39. If a class is derived using private mode then private mode members of base class become
____ of derived class
A. public members
B. private members
C. protected
D. no access

40. What will be the output of the following code?


#include <iostream>
using namespace std;
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:private A
{
public:
void display()
{
x=100;
y=200;
z=300;
}
};
A. x=100,y=200,z=300
B. error for x,y=200,z=300
C. error for x and y,z=300
D. error for x,y and z

41. What will be the output of the following code?


#include <iostream>
using namespace std;

class A
{
private:
int x;
protected:
int y;
public:
int z;

void display()
{
x=10;
y=20;
z=30;
}
};
class B:private A
{

};
int main()
{
B b;
b.display();
return 0;
}
A. The value of x,y and z are assigned as 10,20,30 respectively
B. error for assignment of x
C. error for assignment of x and y
D. error for accessibility of display () function

42. What is the difference between protected and private access specifier?
A. private member is not inheritable and not accessible in derived class.
B. protected member is inheritable and also accessible in derived class.
C. both are inheritable but private is accessible inthe derived class.
D. both are inheritable but protected is not accessible in the derived class.

43. What will be the output of the following code?


#include <iostream>
using namespace std;

class A
{
public:
A()
{
cout<<"base class constructor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class Constructor";
}
};
int main()
{
B b;
return 0;
}
A. base class constructor
B. base class constructor derived class constructor
C. base class constructorDerived class constructor
D. derived class constructor base class constructor

44. If we define a base class constructor with arguments then it is ___ for derived class to have
constructor and pass argument to base class constructor.
A. optional
B. compulsory
C. depends upon the compiler
D. it will generate syntax error because parameterized constructor is not allowed in base class
Arrays

1.What are arrays in the C++?


A. A series of elements of same type placed in continuous block of memory.
B. A series of elements of different type placed in continuous block of memory.
C. A series of elements of same type placed in non-continuous block of memory.
D. A series of elements of different type placed in non-continuous block of memory.

2. The memory address for array can be obtained using ____.


A. a[0]
B. address_of(a)
C. a[1]
D. a

3. Which of the following are characteristics of array?


a. The array contains all the elements of same data type
b. All the elements of the array share the same name and then can be distinguished from one
another by index
c. The name of the array represents the address of the first element of an array
d. All of the above

4. How will you pass the large objects in C++?


A. using call by value method
B. using call by reference method
C. either a or b
D. none of these

5. Which of the following correctly declares an array?


a) int array[10];
b) int array;
c) array{10};
d) array array[10];

6. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined

7) The process of storing the elements in an array is called as


a. initialization of array
b. declaration of array
c. finalization of array
d. none of the above
8) Which of the following correctly declares an array of objects for a class ABC?
a) ABCarray[10];
b) ABC array;
c) array{10};
d) array array[10];

9) How much memory will be allocated to the object obj1 in the following code?
#include<iostream>
using namespace std;
class student
{
int age;
introll_no;
public:
………
....……
};
int main()
{
student s[10];
………..
………..
return 0;
}
a. 10Bytes
b. 20Bytes
c. 40 Bytes
d. No memory is allocated

Memory Allocation for Objects

ONLINE QUESTIONS

1) In C++, dynamic memory allocation is done using ______________ operator

a. calloc()
b. malloc()
c. allocate
d. New

2) Which of the following operator is used to release the dynamically allocated memory in C++?

a. remove
b. free
c. delete
d. both b and c

3) Which of the following is/are valid ways to allocate memory for an integer by dynamic
memory allocation in CPP?

a. int *p = new int(100);


b. int *p; p = new int; *p = 100;
c. int *p = NULL; p = new int; *p=100;
d. All of these

4) During dynamic memory allocation in CPP, new operator returns _________ value if
memory allocation is unsuccessful.

a. False
b. NULL
c. Zero
d. None of these

5) When the memory spaces for the member functions are allocated?

a) when the objects are created


b) when the class are created
c) when member functions are defined as a part of class
d) All of these

6) Why separate memory locations are essential for an object

a) member variables hold different data values for different objects


b) each object in the class has separate member function
c) Both a,b
d) none of these

7) The amount of memory allocated for an object is equal to

a) amount of memory required by member functions of that class


b) amount of memory required by data members of that class
c) amount of memory required by both data members and data functions
d) amount of memory required by the class

8) All the objects of a class share the same copy of

a) data members
b) member functions
c) both data members and member function
d) None of these

9) How will you free the memory allocated by the following program?

#include <iostream>
using namespace std
int main()
{
int *p;
p=new int;
return 0;
}

a) delete(p)
b) delete p
c) delete(int p)
d) delete (p,0)

10) When the memory spaces for the data member are allocated?
a) when the class is specified
b) when the object of the class is declared
c) when the member function is declared
d) None of these

11) How much memory will be allocated to the object obj1 of the following class?
class test
{
float a;
int b;
char c;
}
int main()
{
test obj1;
return 0;
}

a. 8Bytes
b.7Bytes
c. 6Bytes
d. No memory will be allocated
MCQs on Unit 4

1. C++ Inheritance relationship is


a) Association
b) Is-A
c) Has-A
d) None
2.Inheritance allow in C++ Program?
a) Class Re-usability
b) Creating a hierarchy of classes
c) Extendibility
d) All
3. C++ abstract class can contain
a) Pure virtual function
b) Non-virtual function
c) Only pure virtual function
d) Both pure virtual and non-virtual function
4. Following keyword is used before a function in a base class to be overridden in derived class in C++
a) override
b) virtual
c) void
d) none
5. Interface class in C++ is created by
a) Using interface keyword before class
b) Using pure virtual function
c) Using pure virtual function and virtual function both
d) Using class keyword
6. When a class serves as base class for many derived classes, the situation is called:
a) polymorphism
b) hierarchical inheritance
c) hybrid inheritance
d) multiple inheritance
7.Which among the following can show polymorphism?
a) Overloading ||
b) Overloading +=
c) Overloading <<
d) Overloading &&

8. Which problem may arise if we use abstract class functions for polymorphism?
a) All classes are converted as abstract class
b) Derived class must be of abstract type
c) All the derived classes must implement the undefined functions
d) Derived classes can’t redefine the function

9. When the inheritance is private, the private methods in base class are __________ in the derived class
(in C++).

A. Inaccessible
B. Accessible
C. Protected
D. Public

10. Whatwill be the order of execution of base class constructors in the


following method of inheritance.class a: public b, public c {...};
A. b(); c(); a();
B. c(); b(); a();
C. a(); b(); c();
D. b(); a(); c();
11. If 2 classes derive one base class and redefine a function of base class, also overload some
operators inside the class body. Among these two things of function and operator overloading, where
is polymorphism used?

a) Function overloading only

b) Operator overloading only

c) Both of these are using polymorphism

d) Either function overloading or operator overloading because polymorphism can be applied


only once in a program

12. Which of the following advantages we lose by using multiple inheritance?


A. Dynamic binding
B. Polymorphism
C. Both Dynamic binding & Polymorphism
D. None of the mentioned
13. Which is the correct declaration of pure virtual function in C++
1. virtual void func = 0;
2. virtual void func() = 0;
3. virtual void func(){0};
4. void func() = 0;

14. Which one of the following can’t be used for polymorphism?


A. Member functions overloading
B. Static member functions
C. global member function
D. Constructor overloading

15. What is the output of the following code?

class student
{
public :
int marks;
void disp()
{
cout<<”its base class”;
};
class topper:public student
{
public :
void disp()
{
cout<<”Its derived class”;
}
}
void main() { student s; topper t;
s.disp();
t.disp();
}
A. its base class its derived class
B. its base class its derived class
C. its derived class it’s base class
D. none of these
16. Run time polymorphism is achieved only when a ……………….. Is accessed through a
pointer to the base class.
A) static function
B) Real function
C. Member function
D) Virtual function

17. Run time binding is related to

1. Function overriding
2. Operator overloading
3. A&B
4. None

18. In case of inheritance where both base and derived class are having constructor and
destructor, then which if the following are true ?

1. Constructors are executed in their order of derivation


2. Constructors are executed in reverse order of derivation
3. Destructors are executed in their order of derivation
4. Destructors are executed in reverse order of derivation
a. Only 2 ,4
b. Only 1 , 3
c. Only 1 , 4
d. Only 2, 3

19. Predict the output of following code:


#include<iostream>

using namespace std;


class P {
public:
void print() { cout <<" Inside P"; }
};
class Q : public P {
public:
void print() { cout <<" Inside Q"; }
};

class R: public Q { };

int main(void)
{
R r;
r.print();
return 0;
}
(A) Inside P
(B) Inside Q
(C) Compiler Error: Ambiguous call to print()
(D) None of the above

20. Predict the output of following code:

#include<iostream>
using namespace std;

class Base {};

class Derived: public Base {};

int main()
{
Base *bp = new Derived;
Derived *dp = new Base;
}

(A) No Compiler Error


(B) Compiler Error in line “Base *bp = new Derived;”
(C) Compiler Error in line ” Derived *dp = new Base;”
(D) Runtime Error
21. Consider the following class definitions in a hypothetical Object Oriented language
that supports inheritance and uses dynamic binding. The language should not be
assumed to be either Java or C++, though the syntax is similar.
Class P
{ void f(int i)
{ print(i); }
}

Class Q subclass of P
{ void f(int i)
{ print(2*i); }
}
Now consider the following program fragment:
P x = new Q();
Q y = new Q();
P z = new Q();
x.f(1); ((P)y).f(1); z.f(1);
Here ((P)y) denotes a typecast of y to P. The output produced by executing the above
program fragment will be
(A) 1 2 1
(B) 2 1 1
(C) 2 1 2
(D) 2 2 2

22. It is desired to design an object-oriented employee record system for a company.


Each employee has a name, unique id and salary. Employees belong to different
categories and their salary is determined by their category. The functions to get Name,
getld and compute salary are required. Given the class hierarchy below, possible
locations for these functions are: (GATE CS 2004)
i. getld is implemented in the superclass
ii. getld is implemented in the subclass
iii. getName is an abstract function in the superclass
iv. getName is implemented in the superclass
v. getName is implemented in the subclass
vi. getSalary is an abstract function in the superclass
vii. getSalary is implemented in the superclass
viii. getSalary is implemented in the subclass

Choose the best design


(a) (i), (iv), (vi), (viii)
(b) (i), (iv), (vii)
(c) (i), (iii), (v), (vi), (viii)
(d) (ii), (v), (viii)
23. Which of the following is not true in C++ ?

A. “Private” elements of a base class are not accessible by members of its derived class.
B. “Protected” elements of base class are not accessible by members of its derived
class.
C. When base class access specified is “Public”, public elements of the base class become
public members of its derived class.
D. When base class access specified is “Public”, protected elements of a base class become
protected members of its derived class.
24. Which of the following is true?
(A) A “static” member of a class cannot be inherited by its derived class.

(B) A “static” member of a class can be initialized only within the class it is a member of.

(C) A “static” member of a class can be initialized before an object of that class is created.

(D) Since a “static” member of a class is actually a global element, it does not require a
class/object qualifier to access it independently of class/object.

25. Assume that we have constructor functions for both base class and derived class. Now
consider the declaration in

main()

Base *P=New Derived;


In what sequence will the constructor be called?

A. Derived class constructor followed by Base class constructor


B. Base class constructor followed by Derived class constructor
C. Base class constructor will not be called
D. Derived class constructor will not be called

26. If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access

A. only protected and public data of C and B


B. Only protected and public data of C
C. all data of C and private data of A and B
D. public and protected data of A and B and all data of C

27. Which of the following is/are correct with reference to Abstract class and interface?

a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neitehr a nor b are true

28. Which of the following is/are correct with reference to Abstract class and interface?

a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neither a nor b are true

29. Which of the following is used to make an Abstract class?

A. Making at least one member function as pure virtual function


B. Making at least one member function as virtual function
C. Declaring as Abstract class using virtual keyword
D. Declaring as Abstract class using static keyword

30. Which of the following differentiates between overloaded functions and overridden functions
?

A. Overloading is a dynamic or runtime binding and overridden is a static or compile time


binding.
B. Overloading is a static or compile time binding and overriding is dynamic or
runtime binding.
C. Redefining a function in a friend class is called overloading, while redefining a function
in a derived class is called as overridden function.

D. Redefining a function in a derived class is called function overloading, while redefining a


function in a friend class is called function overriding.
Unit V

Templates, Namespaces& Exception handling

Multiple Choice Questions

1. Which value is placed in the base class?

A. Derived values
B. Default type values
C. Both default type & derived values
D. None of the above

2. What is a template?

A. A template is a formula for creating a generic class


B. A template is used to manipulate the class
C. A template is used for creating the attributes
D. None of the above

3. Which of the following best defines the syntax for template function ?

A. template return_type Function_Name(Parameters)


B. template return_type Function_Name(Parameters)
C. Both A and B
D. None of the above

4. Templates are abstract recipe for producing a concrete code, and it is used for

A. Producing functions
B. Producing classes
C. Nothing
D. Both A and B
5.How many parameters are legal for non-type template?

A. 1
B. 2
C. 3
D. 4

6. How many kinds of entities are directly parameterized in c++?

A. 1
B. 2
C. 3
D. 4

7. From where does the template class derived?

A. Regular non-templated C++ class


B. Templated class
C. Both A or B
D. None of the above

8. Can we have overloading of the function templates?

A. Yes
B. No
C. May Be
D. Can't Say

9. A container class is a class whose instances are

A. Containers
B. Functions
C. Strings
D. None of the above

10. Which of the things does not require instantiation?

A. Functions
B. Non virtual member function
C. Member class
D. All of the above

11. Which operator is used to signify the namespace in c++?

A. conditional operator
B. ternary operator
C. scope operator
D. None of the mentioned

12. Identify the incorrect statement?

A. Namespace is used to mark the beginning of the program


B. Namespace is used to mark the beginning & end of the program
C. A namespace is used to separate the class, objects
D. All of the above
13. What is the use of Namespace?

A. To encapsulate the data


B. Encapsulate the data & structure a program into logical units
C. It is used to mark the beginning of the program
D. None of the above

14. What is the general syntax for accessing the namespace variable?

A. namespace::operator
B. namespace,operator
C. namespace#operator
D. namespace$operator

15. The use of Namespace is to structure a program into logical units?

A. TRUE
B. FALSE
C. May Be
D. Can't Say
16. Which of the following is correct option?

A. 43.5478
B. 43
C. 44
D. 30

17. Which keyword is used to access the variable in the namespace?


A. using
B. dynamic
C. const
D. static

18. Which keyword is used to handle the expection?

A. Try
B. Throw
C. Catch
D. None of the above
19. Which is used to throw a exception?

A. Try
B. Throw
C. Catch
D. None of the above

20. Which exception is thrown by dynamic_cast?

A. bad_cast
B. bad_typeid
C. bad_exception
D. bad_alloc

21. How do define the user-defined exceptions?

A. Inherting & overriding exception class functionlity


B. Overriding class functionlity
C. Inherting class functionlity
D. None of the above

22. In nested try block, if inner catch handler gets executed, then __________?

A. Program execution stops immediately.


B. Outer catch handler will also get executed.
C. Compiler will jump to the outer catch handler and then executes remaining executable
statements of main().
D. Compiler will execute remaining executable statements of outer try block and then
the main().

23. Return type of uncaught_exception() is ___________.

A. int
B. bool
C. char *
D. double
24. Which of the following statements are true about Catch handler? i) It must be placed
immediately after try block T. ii) It can have multiple parameters. iii) There must be only
one catch handler for every try block. iv) There can be multiple catch handler for a try
block T. v) Generic catch handler can be placed anywhere after try block.

A. Only i, iv, v
B. Only i, ii, iii
C. Only i, iv
D. Only i, ii

25. If inner catch handler is not able to handle the exception then__________ .

A. Compiler will look for outer try handler


B. Program terminates abnormally
C. Compiler will check for appropriate catch handler of outer try block
D. None of the above

26. Which type of program is recommended to include in try block?

A. Static memory allocation


B. Dynamic memory allocation
C. Const reference
D. Pointer

27. The code of statements which may cause abnormal termination of the program should be
written under_________ block.
a. Try
b. catch
c. Finally
d. None of these

28. Which of the following statements are true about Catch handler?
1. It must be placed immediately after try block T.
2. It can have multiple parameters.
3. There must be only one catch handler for every try block.
4. There can be multiple catch handler for a try block T.
5. Generic catch handler can be placed anywhere after try block.

a. Only 1, 4, 5
b. Only 1, 2, 3
c. Only 1, 4
d. Only 1, 2

29. Exception handlers are declared with ____________ keyword.


a. Try
b. catch
c. throw
d. Finally

30. An exception is thrown using _____________ keyword in CPP.


a. throws
b. throw
c. threw
d. Thrown

31. Which value is placed in the base class?


a. Derived values
b. Default type values
c. Both default type & derived values
d. None of the above

32. What is a template?


a. A template is a formula for creating a generic class
b. A template is used to manipulate the class
c. A template is used for creating the attributes
d. None of the above

33. Which of the following best defines the syntax for template function ?
a. template return_type Function_Name(Parameters)
b. template return_type Function_Name(Parameters)
c. Both A and B
d. None of the above

34. Templates are abstract recipe for producing a concrete code, and it is used for
a. Producing functions
b. Producing classes
c. Nothing
d. Both A and B

35. From where does the template class derived?


a. Regular non-templated C++ class
b Templated class
c. Both A or B
d. None of the above

36. Can we have overloading of the function templates?


a. Yes
b. No
c. May Be
d. Can't Say

37. A container class is a class whose instances are


A. Containers
B. Functions
C. Strings
D. None of the above

38. Which of the things does not require instantiation?


A. Functions
B. Non virtual member function
C. Member class
D. All of the above

39. Pick the incorrect statement for namespaces in C++.


a) Namespace declarations are always global scope
b) Keyword namespace is used at the starting of a namespace definition
c) Namespace has access specifiers like private or public
d) Namespace definitions can be nested

40. Which operator is used for accessing a member of namespace?


a) :
b) ::
c) ->
d) .

41. What is the correct syntax of defining a namespace?


a) namespace name{}
b) Namespace name{};
c) namespace name{};
d) typedef namespace name{} NAME

42. How to print the value of the i variable inside namespace B?

namespace A{
int var = 10;
namespace B{
int i = 15;
}
}
a) cout<<A::i;
b) cout<<B::i;
c) cout<<A::B::i;
d) cout<<i;

43. Irrespective of exception occurrence, catch handler will always get executed.
a)True
b)False

44. An exception can be of only built-In type.


a)True
b)False

45. Functions called from within a try block may also throw exception.
a) True
b) False

46. Which operator is used to signify the namespace in c++?

a) conditional operator
b) ternary operator
c) scope operator
d) None of the mentioned

47. Identify the incorrect statement?

a). Namespace is used to mark the beginning of the program


b). Namespace is used to mark the beginning & end of the program
c) A namespace is used to separate the class, objects
d) All of the above

48. What is the use of Namespace?


a). To encapsulate the data
b) Encapsulate the data & structure a program into logical units
c) It is used to mark the beginning of the program
d) None of the above

49. What is the general syntax for accessing the namespace variable?

a) namespace::operator
b) namespace,operator
c) namespace#operator
d) namespace$operator

50. Which is used to handle the exceptions in c++?


a) catch handler
b) handler
c) exception handler
d)throw

51. Which statement is used to catch all types of exceptions?


a) catch()
b) catch(Test t)
c) catch(….)
d) catch(Test)

52. What will be the output of the following C++ code?

#include <iostream>
#include <typeinfo>

using namespace std;

class Polymorphic {virtual void Member(){}};

int main ()

try

Polymorphic * pb = 0;

typeid(*pb);

catch (exception& e)

cerr << "exception caught: " << e.what() << endl;

return 0;

a) exception caught: std::bad_typeid


b) exception caught: std::bad_alloc
c) exception caught: std::bad_cast
d) exception caught: std::bad_id

53. What is meant by exception specification?


a) A function is limited to throwing only a specified list of exceptions
b) A catch can catch all types of exceptions
c) A function can throw any type of exceptions
d) A try can catch all types of exceptions

54. What will happen when a programs throws any other type of exception other than
specified?
a) terminate
b)arise error
c)run
d)throw

55. What is meant by the template parameter?


a) It can be used to pass a type as an argument
b) It can be used to evaluate a type
c) It can of no return type
d) It can be used to delete a type

56. What is the use of Namespace?


a) To encapsulate the data
b) To structure a program into logical units
c) Encapsulate the data & structure a program into logical units
d) It is used to mark the beginning of the program

57. Which keyword is used to access the variable in the namespace?


a)using
b)static
c) dynamic
d)const

58. Which operator is used for accessing a member of namespace?


a).
b)::
c)->
d)&

58. Can we have overloading of the function templates?


a)Yes
b)No
c)Maybe
d)None of the above

59. Identify the incorrect statement?


a) Namespace is used to mark the beginning of the program
b) A namespace is used to separate the class, objects
c)All of the above
d) None of the above

60. What is the general syntax for accessing the namespace variable?
a) namespace::operator

b) namespace,operator

c) namespace#operator

d) namespace$operator

61. Which of the following is correct option?

#include<iostream>

using namespace std;

namespace lfc1
{

int var = 30;

namespace lfc2

double var = 13.5478;

int main ()

int a;

a = lfc1::var + lfc2::var;

cout << a;

return 0;

}
a)43.54
b)43
c)44
d)30

62. What is the output of this program?

#include <iostream>

using namespace std;

int main()

try

throw 'b';

}
catch (int param)

cout << "Int Exception";

catch (...)

cout << "Default Exception";

cout << "After Exception";

return 0;

a) Default Exception After Exception

b) Int Exception After Exception

c) Int Exception
d) Default Exception
K.K. Wagh Institute of Engineering Education and Research, Nashik
SE (E&TC)
Object Oriented Programming

1. By default, all the files in C++ are opened in _________ mode.


a) Text
b) Binary
c) ISCII
d) VTC

2. What is the return type open() method?


a) int
b) char
c) bool
d) float

3. Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p()
b) get_pos()
c) get_p()
d) tell_pos()

4. Which of these is the correct statement about eof() ?

A. Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.

5. The purpose of a file buffer is:


A. to use memory
B. to speed up input/output
C. to speed up arithmetic operations
D. to protect data

6. ofstream, ifstream, and fstream are:


A. libraries
B. header files
C. built in classes
D. string arrays

7. What will be the output of this program?


using namespace std;
int main ()

{
FILE *fp;
char x[1024];
fp = fopen("find.txt", "r"); // "ayushjain and prateek"
x[0] = getc(fp);
fseek(fp, 0, SEEK_END);
fseek(fp, -7L, SEEK_CUR);
fgets(x, 6, fp);
puts(x);
return 0;
}
A. ayushj
B. yushja
C. ayushja
D. prate

8. Which member function is used to determine whether the stream object is


currently associated with a file?
A. is_open
B. Buf
C. String
D. None of the above

9. The __________ built in class can be used to create files and read information
from them into memory.
A. instream
B. ifstream
C. ofstream
D. istream

10. fseek() should be preferred over rewind() mainly because


A. In rewind, there is no way to check if the operations completed successfully
B. rewind() doesn't work for empty files
C. rewind() does work for empty file
D. All of the above

11. Which of the following true about FILE *fp


A. FILE is a structure and fp is a pointer to the structure of FILE type
B. FILE is a buffered stream
C. FILE is a keyword in C for representing files and fp is a variable of FILE type
D. FILE is a stream

12. In fopen(), the open mode "wx" is sometimes preferred "w" because. i)
Use of wx is more efficient. ii) If w is used, old contents of file are erased and
a new empty file is created. When wx is used, fopen() returns NULL if file
already exists.
A. Only i
B. Only ii
C. Both i & ii
D. None of the above
13. To perform File I/O operations, we must use _____________ header file.
A. < ifstream>
B. < ofstream>
C. < fstream>
D. Any of these

14. How to get position to the nth byte of fileObject ?


A. fileObject.seekg( 'filename',n );
B. fileObject.seekg( n, 'filename' );
C. fileObject.seekg( n );
D. fileObject.seekg( n, ios::app );

15. What must be specified when we construct an object of class ostream?


A. stream
B. streambuf
C. memory
D. None of the mentioned

16. In order, the three-step process of using a file in a C++ program involves:
A. Name the file, open the file, and delete the file
B. Insert a diskette, open a file, and remove the disk
C. Open the existing file, read/write data, close the file
D. Create the file contents, close the file, and name the file

17. Which of the following is used to Open a file for output and move the
read/write control to the end of the file ?
A. ios::ate
B. ios::at
C. ios::ann
D. ios::end

18. What is the use of rewind() function in C?


A. set the position to the beginning point
B. gives current position in the file
C. set the position to desire point
D. None of these
Which of the following keywords is used to control access to a class member?
1 point

A-Default
B-Break
C-Protected
D-Asm

Clear selection

2. Which of the following can access private data members or member functions
of a class?
1 point

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.

Clear selection

3. Which of the following statements is correct?


1 point

A-Data items in a class must be private.


B-Both data and functions can be either private or public.
C-Member functions of a class must be private.
D-Constructor of a class cannot be private.

Clear selection

4. In C++, a function contained within the class is called ?


1 point

A- member function
B- a class function
C- in built
D- none of above

Clear selection

5. _________ is a special character used to mark end of class.


1 point

A- :
B- ;
C-#
D-$

Clear selection

6. The provision of a single interface to entities of different types is called?


1 point

A. polymorphism
B. dimorphism
C. trimorphism
D. none of these

Clear selection

7. Using operation or function in different ways depending on what they are


operating on is called?
1 point

A. classes
B. inheritence
C. polymorphism
D. dimorphism

Clear selection

8. Run time polymorphism is achieved only when a ……………….. Is accessed through


a pointer to the base class.
1 point

A) static function
B) Real function
C. Member function
D) Virtual function

Clear selection

9. A class serves as base class for many derived classes it is called:


1 point

A. polymorphism
B. multipath inheritance
C .hierarchical inheritance
D. none of these

Clear selection

10. The two or more classes serve as base class for a derived class, then this
situation is called .
1 point

A. Polymorphism
B. multiple inheritance
C. encapsulation
D. none of these
Which datatype is used to represent the absence of parameters? (CO1)
1 point

a) int
b) short
c) void
d) float

Clear selection

2. Identify the user-defined types from the following? (CO1)


1 point

a) enumeration
b) classes
c) both a and b
d) int

3. Constructor is executed when __ _ (CO2)


1 point

a) An object goes out of scope.


b) A class is declared
c) An object is created
d) An object is used

4. Which of the following keywords is used to control access to a class


member?(CO2)
1 point

a) protected
b) switch
c) goto
d) for

5. Which operator is used to define the member of a class externally? (CO3)


1 point

A) :
B) ::
C) #
D) None Of The Mentioned

6. With respect to streams >> (operator) is called as __________ (C03)


1 point

A - Insertion operator
B - Extraction operator
C - Right shift operator
D - Left shift operator

7. Which among the following can show polymorphism?


1 point

a) Overloading ||
b) Overloading +=
c) Overloading <<
d) Overloading &&

8. Which of the following advantages we lose by using multiple inheritance? (CO4)


1 point

A. Dynamic binding
B. Polymorphism
C. Both Dynamic binding & Polymorphism
D. None of the mentioned

9. Which of the things does not require instantiation?


1 point

A. Functions
B. Non virtual member function
C. Member class
D. All of the above

10. To perform File I/O operations, we must use _____________ header file.
1 point

A. < ifstream>
B. < ofstream>
C. < fstream>
D. Any of these
Pimpri Chinchwad Education Trust’s
Pimpri Chinchwad College of Engineering
Sector No. 26, Pradhikaran,
Nigdi, Pune – 411 044

MCQ on UNIT 3 & UNIT 4

UNIT 3: Operator Overloading

1. What is operator overloading in C++?

a) Overriding the operator meaning by the user defined meaning for user defined data type

b) Redefining the way operator works for user defined types

c) Ability to provide the operators with some special meaning for user defined data type

d) All of the mentioned

2. What is the syntax of overloading operator + for class A?

a) A operator+(argument_list){}

b) A operator[+](argument_list){}

c) int +(argument_list){}

d) int [+](argument_list){}

3. How many approaches are used for operator overloading?

a) 1

b) 2

c) 3

d) 4

4. Which of the following operator cannot be overloaded?

a) +

b) ?:
c) –

d) %

5.Which of the following operator can be overloaded?

a) ?:

b) ::

c) .

d) ==

6.Which of the following operator cannot be used to overload when that function is declared as
friend function?

a) -=

b) ||

c) ==

d) []

7. Which of the following operator can be used to overload when that function is declared as
friend function?

a) []

b) ()

c) ->

d) |=

8.In case of non-static member functions how many maximum object arguments a unary operator
overloaded function can take?
a) 1

b) 2

c) 3

d) 0

9.In case of non-static member functions how many maximum object arguments a binary
operator overloaded function can take?

a) 1

b) 2

c) 3

d) 0

10. In the case of friend operator overloaded functions how many maximum object arguments a
unary operator overloaded function can take?

a) 1

b) 2

c) 3

d) 0

11. Which is the correct statement anout operator overloading in C++?.

A. Only arithmetic operators can be overloaded

B. Associativity and precedence of operators does not change

C. Precedence of operators are changed after overlaoding

D. Only non-arithmetic operators can be overloaded


12.Which of the following operators cannot be overloaded?

A. .* (Pointer-to-member Operator )

B. :: (Scope Resolution Operator)

C. .* (Pointer-to-member Operator )

D. All of the above

13.While overloading binary operators using member function, it requires ___ argument?

A. 2

B. 1

C. 0

D. 3

14.Which of the following operators should be preferred to overload as a global function rather
than a member method?

A. Postfix ++

B. Comparison Operator

C. Insertion Operator <<

D. prefix ++

15. Which of the following operator functions cannot be global, i.e., must be a member function.

A. new

B. delete

C. Converstion Operator
D. All of the above

16.In case of operator overloading, operator function must be ______ . 1. Static member
functions 2. Non- static member functions 3. Friend Functions

a. Only 2

b. Only 1, 3

c. Only 2 , 3

d. All 1 , 2, 3

17. Scope resolution operator is used______ .

a. to resolve the scope of global variables only

b. to resolve the scope of functions of the classes only

c. to resolve scope of global variables as well as functions of the classes

d. None of these

18. An operator function is created using _____________ keyword.

a. iterator

b. allocator

c. constructor

d. operator

19. How many operators are supported by C++?

A. 30

B. 40
C. 45

D.50

20. correct example of a binary operator is _______.

A. —

B. +

C. ++

D. Dereferencing operator(*)

21. The feature that allows you to use the same function name for separate functions that have
different argument lists is called _____

a. overriding

b. overloading

c. constructing

d. destructing

22. The following operators cannot be overloaded

a) scope resolution operator

b) size of operator

c) conditional operator

d) all of the above

23.The operator function

a) is declared in the public section of the class


b) may be a member function or a friend function

c) both (a) & (b)

d) none of the above

24.The operator functions may be invoked

a) implicitly

b) explicitly

c) both (a) & (b)

d) none of the above

25. The following operator can’t be overloaded

a) unary

b) binary

c) ternary

d) none of the above

26.Which of the following statements regarding operator overloading function is false?

a) While overloading, the semantics of an operator cannot be changed.

b) The operator precedence cannot be changed while overloading.

c) The overloaded operator must have at least one operand that is of user-defined type.

d) You can create new operator symbol.

27.The following operators cannot be overloaded.

a) Logical AND (&&)


b) Subscript operator ([])

c) Equality operator (==)

d) none of the above

28.Which of the following statements regarding operator overloading is false?

a) friend function cannot be used to overload certain operators.

b) Unary operators overloaded by means of friend functions takes no argument

c) Binary operators must explicitly return a value

d) The syntax rules of the operators cannot be overridden.

29.Operator overloading is

a) making c++ operators work with objects

b) giving c++ operators more than they can handle

c) giving new meaning to existing c++ operators

d) making new c++ operators

30. In the following program f() is overloaded. void f(int x) { } int f(signed x) { return 1;} main()
{}

1 point

A - True

B - False

UNIT 4 MCQ

Inheritance and Polymorphism

1. When the inheritance is private, the private methods in base class are __________ in the
derived class (in C++).
A. Inaccessible
B. Accessible
C. Protected
D. Public

Ans : A

2. Which design patterns benefit from the multiple inheritances?

A. Adapter and observer pattern


B. Code pattern
C. Glue pattern
D. None of the mentioned

Ans : A

3. What is meant by multiple inheritance?

A. Deriving a base class from derived class


B. Deriving a derived class from base class
C. Deriving a derived class from more than one base class
D. None of the mentioned

Ans : C

4. What will be the order of execution of base class constructors in the following method of
inheritance.class a: public b, public c {...};

A. b(); c(); a();


B. c(); b(); a();
C. a(); b(); c();
D. b(); a(); c();

Ans : A

5. Which among the following best describes the Inheritance?


a) Copying the code already written
b) Using the code already written once
c) Using already defined functions in programming language
d) Using the data and functions into derived segment

Answer: d
6. How many basic types of inheritance are provided as OOP feature?
a) 4
b) 3
c) 2
d) 1
Answer: a

7. Which among the following best defines single level inheritance?


a) A class inheriting a derived class
b) A class inheriting a base class
c) A class inheriting a nested class
d) A class which gets inherited by 2 classes

Answer: b
8. Which among the following is correct for multiple inheritance?
a) class student{public: int marks;}s; class stream{int total;}; class topper:public student, public
stream{ };
b) class student{int marks;}; class stream{ }; class topper: public student{ };
c) class student{int marks;}; class stream:public student{ };
d) class student{ }; class stream{ }; class topper{ };

Answer: a

9. Which programming language doesn’t support multiple inheritance?


a) C++ and Java
b) C and C++
c) Java and SmallTalk
d) Java

Answer: d

10. Which among the following is correct for a hierarchical inheritance?


a) Two base classes can be used to be derived into one single class
b) Two or more classes can be derived into one class
c) One base class can be derived into other two derived classes or more
d) One base class can be derived into only 2 classes
View Answer

Answer: c
11. Which is the correct syntax of inheritance?
a) class derived_classname : base_classname{ /*define class body*/ };
b) class base_classname : derived_classname{ /*define class body*/ };
c) class derived_classname : access base_classname{ /*define class body*/ };
d) class base_classname :access derived_classname{ /*define class body*/ };

Answer: c
12. Which type of inheritance leads to diamond problem?
a) Single level
b) Multi-level
c) Multiple
d) Hierarchical

Answer: c

13 Compile time polymorphism in C++ language are

A. Operator overloading
B. Function overloading
C. Function overriding
D. B Only
E. A&B

Answer: E

14 C++ abstract class can contain

A. Pure virtual function


B. Non-virtual function
C. Only pure virtual function
D. Both pure virtual and non-virtual function

Answer: D

15 False statements about function overloading is

A. Defining multiple functions with same name in a class is called function overloading
B. Overloaded function must differ in their order and types of arguments.
C. Overloaded functions should be preceded with virtual keyword
D. No statement is false
Answer: C

16 Following keyword is used before a function in a base class to be overridden in derived class in C++

A. override
B. virtual
C. void
D. none

Answer: B

17 Which of the following cannot be overloaded in C++?

A. Increment operator
B. Constructor
C. Destructor
D. New and delete operator

Answer: C

A. Only class student can show polymorphism


B.All class student, topper and average together can show polymorphism
C.Only class student and topper together can show polymorphism
D. none of these

Answer - B

18. What is the output of the following code?

class student
{
public :
int marks;

1 class student
2 {
3 public :
4 int marks;
5 void disp()
6 {
7 cout<<”its base class”;
8 };
9 class topper:public student
10 {
11 public :
12 void disp()
13 {
14 cout<<”Its derived class”;
15 }
16 }
17 void main() { student s; topper t;
18 s.disp();
19 t.disp();
20 }
A. its base class its derived class
B. its base class its derived class
C. its derived class it’s base class
D. none of these

Answer - A

19 what is the output of the following program:

class education
{
char name[10];
public : disp()

1 class education
2 {
3 char name[10];
4 public : disp()
5 {
6 cout<<”Its education system”;
7 }
8 class school:public education
9 {
10 public: void dsip()
11 {
12 cout<<”Its school education system”;
13 }
14 };
15 void main()
16 {
17 school s;
18 s.disp();
19 } }

A. Its school education system


B. its school education system
C. its education system
D. none of these

Answer -A

20. The provision of a single interface to entities of different types is called?


A. polymorphism
B. dimorphism
C. trimorphism
D. none of these

Answer - Click Here:


A

21. Using operation or function in different ways depending on what they are operating on
is called?
A. classes
B.inheritence
C. polymorphism
D. dimorphism

Answer - C

22. Run time polymorphism is achieved only when a ……………….. Is accessed through a
pointer to the base class.
A) static function
B) Real function
C. Member function
D) Virtual function

Answer - D

23. A class serves as base class for many derived classes it is called:
A. polymorphism
B. multipath inheritance

C .hierarchical inheritance
D. none of these

Answer -C

24. The two or more classes serve as base class for a derived class, then this situation is
called .
A. Polymorphism
B. multiple inheritance
C. encapsulation
D. none of these
Answer B

25. The problem may arise if we use abstract class functions for polymorphism in OOP?
A. All classes are converted as an abstract class
B. All the derived classes must implement the undefined functions
C. abstract class must have derived a class
D. Derived classes can’t redefine the function

Answer - C

26. Which of the following is not true for polymorphism?


A. It is a feature of OOP
B. Ease in the readability of a program
C. Helps in redefining the same functionality
D. Increases overhead of function definition always

Answer - D
Pimpri Chinchwad Education Trust’s
Pimpri Chinchwad College of Engineering
Sector No. 26, Pradhikaran,
Nigdi, Pune – 411 044

MCQ on UNIT 1 & UNIT 2

UNIT 1: Foundation of Object-Oriented Programming

Sr. Questions Ans Mark


No. s
Q1 The programming language must have property of _______ if it is a object
oriented programming
A #include files
B functions that return only a single value
C inheritance c 1
D All of the above

Q2 A C++ program has a programmer defined void function.When there is ending


brace of the function like this } , the compiler will return to the statement ___
A immediately above the statement that called the function
B immediately below the statement that called the function b 1
C that called the function
D to the function itself

Q3 The ___ pointer cannot be used with pointers in C++.


A ->
B *
C &
D >> d 1

Q4 The meaning of encapsulation is as follows:


A To inherit properties of base class
B To gridlock of data and code together b 1
C To reduce code length
D To define global variable

Q5 An object compromises of
A behaviour
B state
C none of both
D both of above d 1
Sr. Questions Ans Mark
No. s
Q6 Identify the incorrect statement
A A reference value once defined can be reassigned
B reference is the alternate name of the object
C A reference value once defined cannot be reassigned c 1
D none of the mentioned

Q7 Which of the following is the only technical difference between structures and
classes in C++?
A Member function and data are by default protected in structures but private in
classes.
B Member function and data are by default public in structures but private in
classes.
C Member function and data are by default public in structures but protected in
classes
D Member function and data are by default private in structures but public in d 1
classes.

Q8 Class acquire space in memory..


A True
B False b 1

Q9 If the type specifier of parameters of a function is followed by an ampersand (&),


that function call is
A pass by value
B pass by reference b 1

Q10 Inline functions have the property of


A Speeding up Excecution
B Slowing down execution d 1
C Increasing code size
D first and third option

Q11 If a program is divided into different functions , then


A it makes the program easier to conceptualize
B it may reduce the size of the program
C Both A & B c 1
D none of above
Q12 An argument which cannot be passed to function is
A A constant
B A structure
C A header file. c 1
D A variable

PTO
Sr. No. Questions Ans Marks
Q13 The feature of OOP that allows you to use the same function name for separate
functions that have different argument lists is called
A Overriding
B overloading b 1
C constructing
D Destructing

Q14 The scope resolution operator defines the scope of


A variable
B function
C data member
D first and second d 1

Q15 The * is called as


A member dereferencing operator a 1
B member referencing operator
C scope resolution operator
D None of above

Q16 Which is used to tell the computer that where a pointer is pointing to?
A dereference a 1
B reference
C heap operations
D binary operations

Q17 Which is used to do the dereferencing?


A pointer without asterix
B value without asterix
C pointer with asterix c 1
D value with asterix

Q18 Pick out the correct option.


A References automatically dereference without needing an extra a 1
character
B References automatically dereference with an extra character
C Reference will not dereference

D Reference automatically dereference with extra space and character

Q19 What does the dereference operator will return?


A value equivalent to the value at the pointer address
B value equivalent to the value at the pointer address b 1
C it will return nothing
D it will return boolean values

Sr. No. Questions Ans Marks


Q20 What is the return type of the conversion operator?
A void
B int
C float
D no return type d 1

Q21 How many parameters does a conversion operator may take?


A 0 a 1
B 1
C 2
D many

UNIT 2 : Classes & Objects

1. Constructor is executed when _____.


A. An object goes out of scope.
B. A class is declared
C. An object is created
D. An object is used
2. Which of the following is a valid class declaration?
A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
3. Which of the following keywords is used to control access to a class member?
A. Default
B. Break
C. Protected
D. Asm
4. What is the size of empty class?
A. 0
B. 2
C. 4
D. 1
5. Predict the output of following C++ program
#include<iostream>
using namespace std;

class Empty {};

int main()
{
cout << sizeof(Empty);
return 0;
}

A. A non-zero value
B. 0
C. Compiler Error
D. Runtime Error
6. The keywords private and public used in C++ are known as ………….
A) keyword labels
B) visibility labels
C) declaration labels
D) display labels
7. The variables declared inside the class are known as data members and functions are known as ………….
A) data functions
B) inline functions
C) member functions
D) member variables
8. When the function is defined inside a class, it is treated as ………………….
A) data function
B) inline function
C) member function
D) member variable
9. A ………………. member function can only be called by another function that is member of its class.
A) friend
B) static
C) public
D) private
10. Static variables are associated with the class itself rather than with any class object, they are also known as ………
A) class variables
B) object variables
C) function variables
D) internal variables
11. Static variables are like ………………… as they are declared in a class declaration and defined in the source file.
A) inline member function
B) non-inline member function
C) static member function
D) dynamic member function
12. A …………. can have access to only other static members declared in the same class.
A) constant member function
B) private member function
C) static member function
D) friend function

13. A static member function can be called using the ………………… instead of its objects.
A) variable name
B) function name
C) Class name
D) object name
14. Data members and member functions of a class in C++ program are by default
A. protected
B. public
C. private
D. None

15. Which operator is used to allocate an object dynamically of a class in C++?

A. Scope resolution operator


B. Conditional operator
C. New operator
D. Membership access

16. Which is used to define the member function of a class externally?

A. :
B. ::
C. #
D. None

17. Correct way of creating an object of a class called Car is

A. Car obj;
B. Car *obj = new Car();
C. Only B
D. A & B both

18. True statement about Class and structure in C++ is

A. Default access specifier is private in class and public in structure


B. Way of creating objects of class and structure are different
C. Way of inheriting class and structure are different
D. None

19. Which is Abstract Data Type in C++

A. Class

B. Int

C. Float

D. Array

20. When you create an object of a class A like A obj ; then which one will be called automatically

A. Constructor
B. Destructor

C. Copy constructor

D. Assignment operator

21. When you create an object of a derived class in C++

A. Derived class constructor is called first then the base class constructor
B. Base class constructor is called first then derived class constructor
C. base class constructor will not be called
D. none of the above

22. The class in C++ which act only as a base class and object of it cannot be created is

A. parent class
B. super class
C. abstract class
D. none of the above

23. We can define a new class from an existing class, which of the following is used.

A. Composition
B. Inheritance
C. Constructors
D. Both A and B

24. Data encapsulation and data hiding are key features of. select the correct option.

A. object-oriented language
B. procedural language
C. machine language
D. structural language

25. When a data member of the new class is an object of another class is called ___________.

A. A new class is an aggregate of another


B. A new class is a composite of other objects
C. A new class is inherited
D. None of them
1) Which of the following is not a type of 8) A variable defined within a block is visible
constructor? A. From the point of definition onward in the
A. Copy constructor program
B. Friend constructor B. From the point of definition onward in the
C. Default constructor function
D. Parameterized constructor C. From the point of definition onward in the
Answer: B block
D. Throughout the function
2) Which of the following is not the member of Answer: C
class?
A. Static function 9) Which of the following term is used for a
B. Friend function function defined inside a class?
C. Const function A. Member Variable
D. Virtual function B. Member function
Answer: B C. Class function
D. Classic function
3) Which of the following concepts means Answer: B
determining at runtime what method to
invoke? 10) Which of the following concept of oops
A. Data hiding allows compiler to insert arguments in a
B. Dynamic Typing function call if it is not specified?
C. Dynamic binding A. Call by value
D. Dynamic loading B. Call by reference
Answer: C C. Default arguments
D. Call by pointer
4) The friend functions are used in situations Answer: C
where:
A. We want to have access to unrelated classes 11) How many instances of an abstract class
B. Dynamic binding is required can be created?
C. Exchange of data between classes to take A. 1
place B. 5
D. None of the above C. 13
Answer: D D. 0
Answer: D
5) The keyword friend does not appear in
A. The class allowing access to another class 12) Which of the following cannot be friend?
B. The class desiring access to another class A. Function
C. The private section of a class B. Class
D. The public section of a class C. Object
Answer: C D. Operator function
Answer: C
6) The term __________ means the ability to take
many forms. 13) Which of the following concepts of OOPS
A. Inheritance means exposing only necessary information to
B. Polymorphism client?
C. Member function A. Encapsulation
D. Encapsulation B. Abstraction
Answer: B C. Data hiding
D. Data binding
7) C++ was originally developed by Answer: C
A. Clocksin and Melish
B. Donald E.Knuth
C. Sir Richard Hadlee
D. Bjarne Stroustrup
Answer: D
14) In structured programming, the problem is 21) Preventing direct access of data-members
divided into various ______. of the class from outside world is known as
A. modules ____.
B. functions (A)Polymorphism
C. structures (B)Encapsulation
D. objects (C)Data Hiding
Answer: B (D) scope resolution.
15) In Object-oriented programming, the Answer: C
problem is divided into _____.
A. classes & objects 22) What are cin and cout?
B. functions (A) pointers
C. structures (B) functions
D. modules (C) operator
Answer: A (D) stream objects
Answer: C
16) A class is ____ datatype.
A. primitive 23) Which header file must be included for cin
B. derived and cout?
C. user-defined (A) stdio.h
D. All of these (B) conio.h
Answer: C (C) iostream.h
(D) Both iostream.h and conio.h
17) A class is a collection of ____ and_____. Answer: C
(A)data-members & member functions
(B)data-members, member functions and 24) Creating a new class using one or more
main() existing classes is known as ____.
(C) data-members, member functions,main() (A)Polymorphism
and include statements (B)Encapsulation
(D)None of these (C)overloading
Answer: A (D)inheritance
Answer: D
18) An object is ......
(A)a variable of class datatype. 25) Ability of an operator or function call to
(B)same as a class. take different forms is known as ____.
(C)just like a global variable. (A) Polymorphism
(D)collection of data-members and member (B) Encapsulation
functions. (C) overloading
Answer: A (D)inheritance
Answer: A
19) Wrapping up of data & functions together 26) cout is a/an __________ .
in a class is known as _____. A. operator
(A)Overloading B. function
(B) Data Abstraction C. object
(C)Polymorphism D. macro
(D)Encapsulation Answer: C
Answer: D
27) Which of the following concepts provides
20) Including only necessary details and facility of using object of one class inside
ignoring additional details while defining a another class?
class is known as ____. A. Encapsulation
(A) Overloading B. Abstraction
(B) Data Abstraction C. Composition
(C) Polymorphism D. Inheritance
(D) Encapsulation Answer: C
Answer: B
34) Which of the following is correct about
28) How many types of polymorphisms are class and structure?
supported by C++? A. class can have member functions while
A. 1 structure cannot.
B. 2 B. class data members are public by default
C. 3 while that of structure are private.
D. 4 C. Pointer to structure or classes cannot be
Answer: B declared.
D. class data members are private by default
29) Which of the following is an abstract data while that of structure are public by default.
type? Answer: D
A. int
B. double 35) Which of the following concepts means
C. string wrapping up of data and functions together?
D. Class A. Abstraction
Answer: D B. Encapsulation
C. Inheritance
30) A __________ is a special method used to D. Polymorphism
initialize the instance variable of a class. Answer: B
A. Member function
B. Destructor 36) Which of the following concepts means
C. Constructor waiting until runtime to determine which
D. Structure function to call?
Answer: C A. Data hiding
B. Dynamic casting
31) Which of the following concepts means C. Dynamic binding
adding new components to a program as it D. Dynamic loading
runs? Answer: C
A. Data hiding
B. Dynamic typing 37) Which of the following operator is
C. Dynamic binding overloaded for object cout?
D. Dynamic loading A. >>
Answer: D B. <<
C. +
32) Which of the following statement is D. =
correct? Answer: B
A. A constructor is called at the time of
declaration of an object. 39) Which of the following is the correct class
B. A constructor is called at the time of use of of the object cout?
an object. A. iostream
C. A constructor is called at the time of B. istream
declaration of a class. C. ostream
D. A constructor is called at the time of use of a D. ifstream
class. Answer: C
Answer: A
40) Which of the following cannot be used with
33) Which of the following approach is adapted the keyword virtual?
by C++? A. class
A. Top-down B. member functions
B. Bottom-up C. constructor
C. Right-left D. destructor
D. Left-right Answer: C
Answer: B
41) Which of the following functions are
performed by a constructor? 47) Which one of the following options is
A. Construct a new class correct?
B. Construct a new object A. Friend function can access public data
C. Construct a new function members of the class.
D. Initialize objects B. Friend function can access protected data
Answer: D members of the class.
C. Friend function can access private data
42) Which of the following is the correct way of members of the class.
declaring a function as constant? D. All of the above.
A. const int ShowData(void) { /* statements */ Answer: D
}
B. int const ShowData(void) { /* statements */ 48) Which of the following statements is
} correct in C++?
C. int ShowData(void) const { /* statements */ } A. Classes cannot have data as protected
D. Both A and B members.
Answer: C B. Structures can have functions as members.
C. Class members are public by default.
43) Which of the following statement is D. Structure members are private by default.
correct? Answer: B
A. C++ allows static type checking.
B. C++ allows dynamic type checking. 49) Which of the following access specifier is
C. C++ allows static member function be of used as a default in a class definition?
type const. A. protected
D. Both A and B. B. public
Answer: D C. private
D. friend
44) Which of the following header file includes Answer: C
definition of cin and cout?
A. istream.h 50) What is correct about the static data
B. ostream.h member of a class?
C. iomanip.h A. A static member function can access only
D. iostream.h static data members of a class.
Answer: D B. A static data member is shared among all the
object of the class.
45) What will happen if a class is not having C. A static data member can be accessed
any name? directly from main().
A. It cannot have a destructor. D. Both A and B.
B. It cannot have a constructor. Answer: D
C. It is not allowed.
D. Both A and B. 51) Which of the following provides a reuse
Answer: D mechanism?
A. Abstraction
46) Which one of the following is correct about B. Inheritance
the statements given below? C. Dynamic binding
All function calls are resolved at compile- D. Encapsulation
time in Procedure Oriented Programming. Answer: B
All function calls are resolved at compile-
time in OOPS. 53) Which of the following statement is
A. Only II is correct. correct?
B. Both I and II are correct. A. Class is an instance of object.
C. Only I is correct. B. Object is an instance of a class.
D. Both I and II are incorrect. C. Class is an instance of data type.
Answer: C D. Object is an instance of data type.
Answer: B
59) Inline Functions are invoked at
53) The process of building new classes from A. Run time
existing one is called B. Compile time
A. Structure C. Depends on how it is invoked
B. Inheritance D. Both b and c above
C. Polymorphism Answer: B
D. Template
Answer: B 60) which of the following operator is used to
define member function outside the class?
54) In a class, member variables are often A. ::
called its _________, and its member functions are B. ?
sometimes referred to as its behaviour, or C. :?
____________. D. %
A. attributes, methods Answer: A
B. none of these
C. values, morals 61) function call mechanism that passes
D. data, activities arguments to a function by passing a copy of
Answer: A the values of the arguments is __________
(A)call by name
55) Which of these keywords are access (B)call by value
specifiers? (C)call by reference
A. near and far (D)call by value result
B. opened and closed Answer: B
C. table and row
D. private and public 62) Data members which are static
Answer: D (A)cannot be assigned a value
(B)can only be used in static functions
56) An Object can be declared prior to the class (C)cannot be defined in a Union
definition (D) can be accessed outside the class
A. True Answer: B
B. False:
Answer: False 63) Which of the following is false for cin?
(A)It represents standard input.
57) Use of __________ protects data from (B)It is an object of istream class.
inadvertent modifications (C)It is a class of which stream is an object.
A. protect() member function (D)Using cin the data can be read from user’s
B. private access specifier terminal
C. class protection operator, @ Answer: C
D. none of these
Answer: B 64) It is possible to declare as a friend
(A) a member function
58) A suitable place to store Class declarations (B) a global function
is _______. (C) a class
A. none of these (D) all of the above
B. their own header files Answer: D
C. Auxiliary .cpp file
D. main .cpp files, along with function 65) Given a class named Book, which of the
definitions following is not a valid constructor?
(A)Book ( ) { }
Answer: B (B)Book ( Book b) { }
(C)Book ( Book &b) { }
(D)Book (char* author, char* title) { }
Answer: B
66) How many constructors can a class have? 71) Which of the following statements are true
(A) 0 in c++?
(B) 1 (A) Classes cannot have data as public
(C) 2 members
(D) any number (B) Structures cannot have functions as
Answer: D members
(C) Class members are public by default
66) The new operator (D) None of these
A) returns a pointer to the variable Answer: B
B) creates a variable called new
C) obtains memory for a new variable 72) The following can be declared as friend in a
D) tells how much memory is available class
Answer: C (A) an object
(B) a class
67) A static function (C) a public data member
A. should be called when an object is destroyed (D) a private data member
B. is closely connected with and individual Answer: B
object of a class
C. can be called using the class name and 73) A copy constructor takes
function name (A) no argument
D. is used when a dummy object must be (B) one argument
created (C) two arguments
Answer: C (D) arbitrary no. of arguments
Answer: B
68) We can output text to an object of class
ostream using the insertion operator<< 74) Which can be passed as an argument to a
because function?
(A) the ostream class is a stream (A) constant
(B) the insertion operator works with all (B) expression
classes (C) another function
(C) we are actually outputting to cout (D) all of the above.
(D) the insertion operator is overloaded in Answer: A
ostream
Answer: D 75) Member functions, when defined within
the class specification:
69) Which of the following is not the (A) are always inline.
characteristic of constructor ? (B) are not inline.
(A) They should be declared in the public (C) are inline by default, unless they are too big
section. or too complicated.
(B) They do not have return type. (D) are not inline by default.
(C) They can not be inherited. Answer: A
(D) They can be virtual.
Answer: D 76) An entity representing some
characteristics and behaviour is-
70) A class defined within another class is: a) object
(A) Nested class b) class
(B) Inheritance c) struct
(C) Containership d) none of the above
(D) Encapsulation Answer: A
Answer: A
77) Which of the following is not the feature of 84) Which of the following features of object
OOPs? oriented programming is false?
a) Data Encapsulation a) Data is hidden and is not available to
b) Inheritance external functions.
c) Polymorphism b) New data & functions can be added easily.
d) None of the above c) Objects may communicate with each other
Answer: D through functions.
d) Emphasis is on the procedure rather than
78) The wrapping up of data and functions into data.
a single unit is Answer: D
a) Data Abstraction
b) Data Encapsulation 85) The following is the C++ style comment
c) Both (a) & (b) a) //
d) None of the above b) /*..*/
Answer: B c) –
d) None of the above
79) Which of the following feature supports Answer: A
reusability and extensibility of classes?
a) Inheritance 86) Which of the following statements is false?
b) Overloading a) Every C++ program must have a main().
c) Polymorphism b) In C++, white spaces and carriage returns
d) None of the above are ignored by the compiler.
Answer: A c) C++ statements terminate with semicolon.
d) Main() terminates with semicolon.
80) Inheritance is ………..in nature. Answer: D
a) Intransitive
b) Transitive 87) An identifier in C++
c) Both (a) & (b) a) Must begin with a letter only
d) None of the above b) Is not differentiated by cases
Answer: B c) Contains all characters as significant
81) ………… is the ability for a message or data d) None of the above
to be processed in more than one form Answer: C
a) Class
b) Abstraction 88) ………. Provides a value for a variable
c) Polymorphism a) declaration statement
d) None of the above b) assignment statement
Answer: C c) definition statement
d) None of the above
82) The smallest individual unit in a program is Answer: B
………
a) Keyword 89) A collection of variables referred under one
b) Identifier name
c) Token a) Structure
d) None of the above b) Class
Answer: C c) Union
d) None of the above
83) Which of the following features of Answer: A
procedure oriented programming is false
a) Large programs are divided into small or 90) A memory location shared by two or more
units called functions. different variables
b) Employs bottom-up approach in program a) Structure
design. b) Class
c) Most of the functions share global data. c) Union
d) None of the above. d) None of the above
Answer: B Answer: C
91) The constants defined using enum 98) << operator is
keyword are a) stream insertion operator
a) Symbols b) stream extraction operator
b) Enumerators c) left shift operator
c) Keywords d) None of the above
d) None of the above Answer: A
Answer: B
99) “H” is an example of
92) The operator ?: is a) character literal
a) Logical operator b) string literal
b) Relational operator c) variable
c) Conditional operator d) None of the above
d) Arithmetic operator Answer: B
Answer: C
100) Which of the following statements
93) A loop containing other loop is regarding comments is false?
a) Nested a) /*..*/
b) Inner b) Comment beginning with // extends to the
c) Outer end of the line
d) None of the above c) Comments may be nested
Answer: A d) Comments are used to describe a program
Answer: C
94) The following statement forces the next
iteration of the loop to take place 101) C++ is
a) break a) Procedural programming language
b) continue b) Structural programming language
c) goto c) Object oriented programming language
d) None of the above d) None of the above
Answer: B Answer: C

95) gets() function is available in 102) y=x=2; in C++ will result in


a) stdio.h a) compilation error
b) string.h b) runtime error
c) ctype.h c) assignment of value to x then to y
d) stdlib.h d) None of the above
Answer: A Answer: C

96) In C++, the statements are enclosed within 103) 31. In C++, ………. is the statement
a) parenthesis terminator
b) square brackets a) semicolon
c) curly brackets b) colon
d) None of the above c) new line
Answer: C d) None of the above
Answer: A
97) The following tells the compiler where the
program begins 104) Modules operator (%) has higher
a) Function prototype precedence than
b) Forward declaration of class a) Divide (/) operator
c) main() b) Multiply (*) operator
d) None of the above c) Negation (unary minus)
Answer: C d) Bitwise left shift operator
Answer: C
105) The result of the following statement is 110) Data members and member functions are
int y = 7; enclosed within
int ans = ++y; a) class
cout<<”ans=”<<ans; b) structure
cout<<”y”<<y; c) union
a) ans=7, y=7 d) None of the above
b) ans=8,y=7 Answer: A
c) ans=8,y=8;
d) none of the above 111) Inline functions are
Answer: C a) Declared in the class defined outside the
class
106) Consider the following if construct b) Defined outside the class using keyword
If(x=0) intime
cout<<”Inside loop!”; c) Defined inside the class using keyword inline
cout<<”Outside loop”; d) None of the above
The result of the above code segment is. Answer: B
a) inside loop
b) outside loop 112) The default class access scope is
c) both (a) & (b) a) Private
d) none of the above b) Public
Answer: B c) Protected
d) None of the above
107) The result of 2 & 3 is Answer: A
a) 2
b) 3 113) The default scope for a structure is
c) 5 a) Private
d) none of the above b) Public
Answer: A c) Protected
d) None of the above
108) Which of the following statements Answer: B
regarding enumerators is false?
a) Enumeration is an alternative method for 114) The private data members of a class are
naming integer constants/ accessible
b) An enumerator value can’t be changed in a a) Directly to objects of that class
program b) Only to the member functions
c) An integer value may be assigned to an c) To any function defined outside a class
enumerated variable d) None of the above
d) An enum defined within a structure is local Answer: B
to the structure
Answer: C 115) The objects can directly access
a) Public members
109) Which of the following statements is b) Private members
false? c) Both (a) & (b)
a) typedef defines new data types d) None of the above
b) Using typedef does not replace the standard Answer: A
C++ data type name with the new name
c) The new name defined by typedef, can be 116) The following is a valid statement in C++
used as a type for another typedef a) int x=(int)2.50;
d) None of the above b) int x=int(2.50);
Answer: A c) Both (a) & (b)
d) None of the above
Answer: C
117) Which of the following operator can be 123) When a member function of a class call
overloaded another member function, it is
a) Member access operator ( . & .*) a) Nesting of classes
b) Conditional operator (?:) b) Nesting of functions
c) Scope resolution operator (::) c) Nesting of objects
d) None of the above d) None of the above
Answer: D Answer: B

118) Using same function name to perform 124) A function defined inside a class is called
different tasks is a) A class function
a) Function polymorphism b) A friend function
b) Runtime polymorphism c) A member function
c) Function prototype d) None of the above
d) None of the above Answer: C
Answer: A
125) Information is made shareable through
119) Default argument is a) inheritance
a) Specified in function definition b) data encapsulation
b) Specified in function declaration c) data abstraction
c) Specified from left to right d) none of the above
d) None of the above Answer: A
Answer: B
126) Functions can returns
120) What is wrong with the following a) arrays
statement? b) reference
float s_interest (float principal, int rate=0.25, c) object
int time); d) all of the above
a) variables must not be specified in function Answer: D
prototype
b) arguments may only be defaulted from right 127) The memory for date members is
to left allocated
c) the default value must be specified when a) When a class is defined
making a function call b) When an object is initialized
d) none of the above c) When an object is created
Answer: B d) None of the above
Answer: B
121) Which of the following statements
regarding function overloading is not true. 128)The memory for member functions is
a) If is used to handle different data types at allocated
one place a) When a class is defined
b) When making a function call, if no exact b) When a object is created
match is found, promotion is the only criteria c) When an object is initialized
to find a match. d) None of the above
c) The default arguments can not be used Answer: A
instead of overloading
d) Unrelated functions should not be 129) The dot operator relates
overloaded a) A class member and a class object
Answer: C b) A class object and a class
122) The private members of a class c) A class and a member of that class
implement the OOP concept of d) A class object and member of that class
a) Data abstraction Answer: D
b) Data hiding
c) Message passing
d) None of the above
Answer: B
130) A class having another class definition is 137) new operator is used
a) Nested class a) to define a new variable
b) Subordinate class b) to create a new data type
c) Enclosing class c) to allocate memory dynamically
d) None of the above d) none of the above
Answer: C Answer: C

131) A class whose member functions are 138) A constructor function is generally
friends of other class is defined
a) Friend class a) In the public section of a class
b) Abstract class b) In the private section of a class
c) Virtual class c) In the protected section of a class
d) None of the above d) None of the above
Answer: A Answer: A

132) The data members of a class are 139) A class having no public constructors is
initialized a) A private class
a) in class definition b) A public class
b) by a non-member function c) An abstract class
c) through constructor function when a class d) None of the above
object is created Answer: A
d) none of the above
Answer: C 140) If a constructor function is defined in
private section of a class, then
133) A constructor function is a) The object cannot be created
a) A friend function to a class b) Only member functions and friends may
b) A member function with the same name as declare objects of the class
its class c) Both (a) & (b)
c) A non-member function d) None of the above
d) None of the above Answer: C
Answer: B
141) A constructor with no argument is
134) An enumerated type is composed of a) Default constructor
a) Integer values with user defined name b) Parameterized constructor
b) Variables of different data types c) Copy constructor
c) Constant numeric values d) None of the above
d) None of the above Answer: A
Answer: A
142) If default arguments are provided to a
135) In C++, the arguments by default are constructor function, then it becomes
passed by a) Default constructor
a) call be reference b) Copy instructor
b) call be value c) Parameterized constructor
c) both (a) & (b) d) None of the above
d) none of the above Answer: A
Answer: B
143) The class of which the objects are not
136) is an example of instantiated is
a) unary operator a) Abstract class
b) binary operator b) Virtual class
c) ternary operator c) Static class
d) none of the above d) None of the above
Answer: C Answer: A
144) && denotes 151) Which of the following statements
a) logical OR regarding constructor is false?
b) logical AND a) A constructor may be defined static
c) Bitwise AND b) Constructor can have default arguments
d) None of the above c) Member functions may be invoked from
Answer: B within a constructor
d) None of the above
145) The parameterized constructor Answer: A
a) Needs initial values as arguments during
creation of an object 152) The antonym of constructor is
b) Can be invoked explicitly only a) Creator
c) Can be invoked implicitly only b) Destructor
d) None of the above c) Destroyer
Answer: A d) None of the above
Answer: B
146) Explicit call to a constructor means
a) Providing the constructor name explicitly to 153) Variable …………. of void type
invoke it a) May be declared
b) Not providing the construction name at all b) Cannot be declared
c) Is the shorthand method c) Can be initialized
d) None of the above d) None of the above
Answer: A Answer: B

147) Classes in C++ are 154) A destruction function


a) Fundamental data type a) Takes no argument and has no return type
b) Primitive data type not even void
c) Desired data type b) Has name similar to that of class, preceded
d) None of the above by tilde(~) symbol
Answer: C c) Is used to destruct an object, constructed
through constructor function
148) A copy constructor is called d) All of the above
a) When an object is defined and initialized Answer: D
with another object
b) When an object is passed by value 155) Which of the following statements
c) When a function returns an object regarding destructor function is false?
d) All of the above a) Destructors do not accept any arguments,
Answer: D nor do they return any values
b) Destructors can be inherited
149) Which of the following regarding c) Member functions may be called from within
constructor function is false? a destructor
a) Constructor functions don’t have return d) Destructor functions are called
type, not even void automatically when an object is destroyed
b) Constructors can’t be inherited Answer: B
c) We can refer to their addresses
d) Constructors cannot be virtual 156) Function overloading
Answer: C a) Involves several function definitions under
one name, but different argument types
150) If new operator is used, then the b) Implements polymorphism
constructor function is c) Reduces the number of comparison in a
a) Parameterized constructor program, hence increases the execution speed
b) Copy constructor of a program
c) Dynamic constructor d) All of the above
d) Default constructor Answer: D
Answer: C
157) The signature of function is
a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above
Answer: A

158) Overloading of constructor function


a) is similar to function overloading
b) different from an overloaded function as it
can’t return a value
c) not permitted in C++
d) none of the above
Answer: B

159) The binding of a function call at runtime is


a) Static binding
b) Early binding
c) Late binding
d) Runtime binding
Answer: C

160) The process of giving special meaning to


an operator is
a) Operator overloading
b) Operator mechanism
c) Operator definition
d) None of the above
Answer: A

161) What is a comment in c++?


a) comments are parts of the source code
disregarded by the compiler
b) comments are executed by compiler to find
the meaning of the comment
c) comments are executable
d) none of the mentioned
Answer: a

162) What type of comments does c++


support?
a) single line
b) multi line
c) single line and multi line
d) none of the mentioned
Answer: C

163) What is the use of the indentation in c++?


a) distinguishes between comments and code
b) r distinguishes between comments and
outer data
c) both a and b
d) none of the mentioned
Answer: A
OOP UNIT-1

C is procedure oriented programming language while C++ is object oriented programming


(OOP) language. Before the initial standardization in 1998, C++ was developed by Danish
computer scientist Bjarne Stroustrup at Bell Labs since 1979 as an extension of the C
language.

Features of OOP -
Class (blueprint )
Object ( instance of class or variable of class)
Encapsulation( binding data and functions together as one unit)
Abstraction(Data abstraction refers to providing only essential information to the outside world
and hiding their background details)
Polymorphism ( Ability to take more than one form)
Inheritance( Code reusability)
Dynamic Binding( determining method to invoke at run time )

32 keywords in c++
Using namespace std;
Here, std is the namespace where ANSI C++ standard class libraries are defined.
cin and cout belongs to std namespace

Names given to functions and variables are known as identifiers.


Constants are data items that do not change their value during the execution of the program.
Example :Integer Constants, Character constants, Floating-constants, Strings, Operators

In C++, stream insertion operator << is used for output ie cout<< data;
In C++, stream extraction operator >> is used for input ie cin>>data;

Reference variable in C++: When a variable is declared as a reference, it becomes an alternative


name for an existing variable. Example
int x = 10;
int &ref = x;

Scope Resolution Operator (:: Operator) :


:: is known as Scope Resolution Operator. Use is to access global variable inside main() and to
relate variables and function defined outside class as part of class.

Inline functions: Inline function is a function that is expanded in line when it is called. When the
inline function is called whole code of the inline function gets inserted or substituted at the point
of inline function call.

̳this„ pointer:
THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which
differentiates between the current object with the global object. Basically, it refers to the current
object.
In call by value method, the value of the actual parameters is copied into the formal parameters.
The call by reference method of passing arguments to a function copies the address of an
argument into the formal parameter

Function Overloading:
Function overloading is a feature in C++ where two or more functions can have the same name
but different parameters. In Function Overloading ―Function‖ name should be the same and the
arguments should be different. Function overloading is defined as a normal function, but it has
the ability to perform different tasks. It allows creation of several methods with the same name
which differ from each other by type of input and output of the function.
Example:
void add(int& a, int& b);
void add(double& a, double& b);
void add(struct bob& a, struct bob& b);

Operator overloading is a function where different operators are applied and depends on the
arguments. Operator,-,* can be used to pass through the function, and it has their own
precedence to execute. Overloaded operators are functions with special names: the keyword
"operator" followed by the symbol for the operator being defined. Like any other function, an
overloaded operator has a return type and a parameter list.
Example: Unary operator overloading like ++ or – operator

new and delete are memory management operators in C++. new operator is used to create new
memory and delete to delete memory allocated

MCQ

What does modularity mean?


a) Hiding part of program
b) Subdividing program into small independent parts
c) Overriding parts of program
d) Wrapping things into single unit
Answer:

What is the size of wchar_t in C++?


A. 2
B. 4
C. 2 or 4
D. based on the number of bits in the system
ANSWER: A
Pick the odd one out
A. array type
B. character type
C. boolean type
D. integer type
ANSWER: A

C++ programming follows ____________


a. bottom-up approach
b. top down approach
3. vertical approach
4. None of above
Answer: a

Objects are basic ______ entities in an object oriented system


a. pseudo
b. run-time
c. random
d. None of above
Ans: b

The wrapping up of data and functions into a single unit (called class) is known as__________
a. polymorphism
b. inheritance
c. encapsulation
d. None of above
Answer: c

Attributes of a class are called as ........


A) Member functions
B) Data members
C) Objects
D) All of above
Ans: B

____________means the ability to take more than one form


1. Abstraction
2. Encapsulation
3. Polymorphism
4. Dynamic binding
Answer: 3
__________means that the code associated with given procedure is not known untill the time of
call at run-time.
1. Abstraction
2. Encapsulation
3. Polymorphism
4. Dynamic binding
Answer: 4

Which feature of OOPS described the reusability of code?


1. Abstraction
2. Encapsulation
3. Polymorphism
4. Inheritance
Answer: 4

Which definition best defines the concept of abstraction?


a. Hides the important data
b. Hides the implementation and showing only the features
c. Hiding the implementation
d. Showing the important data
Ans: b

What is the purpose of the keyword inline?


a. It allows one line function declaration
b. It causes the replacement of function calls by the code from the function
c. It indicates function declaration
d. It tells compiler to use that function in the same source code file
Answer: B

What is class in c++ ?


A. When you define a class, you define a blueprint for a data type.
B. When you define a class, you add more functionality.
C. When you define a class, you define the logic.
D. When you define a class, you make debugging.
Answer: A

What is object in C++ ?


A. Object is part of syntax of a class.
B. Object is datatype of a class.
C. Object is an instance of a class.
D. Object is function of a class.
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 statements is correct?
A-Data items in a class must be private.
B-Both data and functions can be either private or public.
C-Member functions of a class must be private.
D-Constructor of a class cannot be private.
Answer: B

In C++, a function contained within the class is called ?


A- member function
B- a class function
C- a method
D- none of above
Answer: A

______________means we can use the same function name to create functions that perform a
variety of different tasks.
a. Polynomials
b. Function overloading
c. Namespace
d. None of above
Answer: b

Name the function whose definition can be substituted at a place where its function call is made
_________
a) friends function
b) inline function
c) volatile function
d) external function

Answer: b
Which among the following is true?

a) this pointer is passed explicitly when member functions are called


b) this pointer is passed implicitly when member functions are called
c) this pointer is passed with help of pointer member functions are called
d) this pointer is passed with help of void pointer member functions are called
Answer: b

Which of the following is the scope resolution operator?


a) .
b) *
c) ::
d) ~

Answer: c
The operator <<
is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: A

Which one of the following is not a valid reserved keyword in C++?


A) virtual
B) public
C) implicit
D) private
Ans: C

Which of the following data type does not return anything?


A) int
B) short
C) long
D) void
Ans: D

Which of the following statement is correct?


A) C++ enables to define functions that take constants as an argument
B) We cannot change the argument of the function that that are declared as constant.
C) Both A and B.
D) We cannot use the constant while defining the function
Ans : C

Classes are useful because they


A) Can closely model objects in the real world.
B) Permit data to be hidden from other classes.
C) Bring together all aspects of an entity in one place.
D) Options A, B and C
Ans: D

A function argument is
A) a variable in the function that receives a value from the calling program.
B) a way that functions resist accepting the calling program‟s values.
C) a value sent to the function by the calling program.
D) a value returned by the function to the calling program.
Ans: C
>> operator is called
A. Insertion operator
B. Extraction operator
C. Object
D. Function
ANSWER: B

Everything defined at the program scope level (ie. outside functions and classes) is said to be
_______
A) local scope
B) regional scope
C) global scope
D) static scope
Answer: C

Which of the following is false for cin?


(A) It represents standard input.
(B) It is an object of istream class.
(C) It is a class of which stream is an object.
(D) Using cin the data can be read from user‟s terminal.
Answer: C

cin object in c++ corresponds to the


A. standard input stream
B. standard output stream
C. Iterative statement
D. Function
ANSWER: A

To display output; what is used in C++


A. cout
B. cin
C. header file
D. class
ANSWER: A

Function prototype is also called


A. Function declaration
B. Function definition
C. Function call
D. Return type
ANSWER: A
Inline function should be used
A. Small set of code
B. Large set of code
C. Friend function
D. For main() function
ANSWER: A

Static variable should be defined


A. Inside the function
B. Outside the function
C. In the function call
D. Anywhere
ANSWER: B

Parameters associated with function call are called


A. Actual parameter
B. Formal parameter
C. Global parameter
D. Auto parameter
ANSWER: A

If function does not return any value then its return type is
A. Int
B. Float
C. Void
D. Char
ANSWER: C

Which method of parameter passing does not change the original variable
A. Call by value
B. Call by reference
C. Call by pointers
D. Both b and c
ANSWER: A

C++ was originally developed by;


A. Clocksin and Mellish
B. Donald E. Knuth
C. Sir Richard Hadlee
D. Bjame Stroustrup
ANSWER: D

cout stands for


A. class output
B. character output
C. common output
D. call output
ANSWER: C

Which of the following is a correct comment?


A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
ANSWER: C

What is encapsulation?
A. It is collection of similar data items
B. It is combination of similar data items and the function
C. It is the combination of data items and function
D. It is the division of program into independent module
ANSWER: B

A variable is defined within a block in a body of a function. Which of the following are true?
A) It is visible throughout the function.
B) It is visible from the point of definition to the end of the program.
C) It is visible from the point of definition to the end of the block.
D) It is visible throughout the block.
Answer : D.

Which of the following can not be used as identifiers?


A. Letters
B. Digits
C. Underscores
D. Spaces
ANSWER: D

What does C++ append to the end of a string literal constant?


a. a space
b. a number sign (#)
c. an asterisk (*)
d. a null character
Answer:d

An array element is accessed using


a. a first-in-first-out approach
b. the dot operator
c. a member name
d. an index number
Answer:d
Which of the following, if any, are valid names for variables?
a. class
b friend
c. void
d. None of the above is valid names for variables
Answer:d

What does your class can hold?


a) data
b) functions
c) both a & b
d) none of the mentioned
Answer:c

The fields in the class in c++ program are by default


a) protected
b) private
c) public
d) none of the mentioned
Answer:b

How to access the object in the class?


a) scope resolution operator
b) ternary operator
c) direct member access operator
d) none of the mentioned
Answer:c

Pick out the other definition of objects.


a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class
Answer: d

Objects may communicate with each other through


a. Data
b. Methods
c. Object
d. Classes
Answer: b

When the code to be linked with the call is known at compile time that situation is called as
a. Binding
b. late binding
c. static binding
d. dynamic binding
Answer:c
The signature of function is
a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above
Answer: a

In C++, dynamic memory allocation is accomplished with the operator ____


a) new
b) this
c) malloc( )
d) delete
Answer: a

What type of comments does c++ support?


a) single line
b) multi line
c) single line and multi line
d) none of the mentioned
Answer: c
The members of a class, by default, are
a) public
b) protected
c) private
d) mandatory to specify
Answer: c

A class defined within another class is:


a) Nested class
b) Inheritance
c) Containership
d) Encapsulation
Answer: a

Which of the following ways are legal to access a class data member using this pointer?
a) this.x
b) *this.x
c) *(this.x)
d) (*this).x
Answer:d

this pointer
a) implicitly points to an object.
b) can be explicitly used in a class.
c) can be used to return an object.
d) All of the above.
Answer:d
What are arrays in the C++?
A. A series of elements of same type placed in continuous block of memory.
B. A series of elements of different type placed in continuous block of memory.
C. A series of elements of same type placed in non-continuous block of memory.
D. A series of elements of different type placed in non-continuous block of memory.
Answer: A

Which of the following are characteristics of array?


a. The array contains all the elements of same data type
b. All the elements of the array share the same name and then can be distinguished from one
another by index
c. The name of the array represents the address of the first element of an array
d. All of the above
Answer: d

How will you pass the large objects in C++?


A. using call by value method
B. using call by reference method
C. either a or b
D. none of these
Answer: B

Which of the following correctly declares an array?


a) int array[10];
b) int array;
c) array{10};
d) array array[10];
Answer: A

In structured programming, the problem is divided into various ______.


A. modules
B. functions
C. structures
D. objects
Answer: B

The smallest individual unit in a program is ………


a) Keyword
b) Identifier
c) Token
d) None of the above
Answer: C
What is the associativity of add(+);
a) right to left
b) left to right
c) both of these
d) None of the mentioned
Answer:b

Which operator is having the highest precedence in c++?


a) array subscript
b) Scope resolution operator
c) static_cast
d) dynamic_cast
Answer:b

In C++, the statements are enclosed within


a) parenthesis
b) square brackets
c) curly brackets
d) None of the above
Answer: C

Modules operator (%) has higher precedence than


a) Divide (/) operator
b) Multiply (*) operator
c) Negation (unary minus)
d) Bitwise left shift operator
Answer: C

The result of 2 & 3 is


a) 2
b) 3
c) 5
d) none of the above
Answer: A

The following is a valid statement in C++


a) int x=(int)2.50;
b) int x=int(2.50);
c) Both (a) & (b)
d) None of the above
Answer: C

Functions can returns


a) arrays
b) reference
c) object
d) all of the above
Answer: D

In C++, dynamic memory allocation is done using ______________ operator


a. calloc()
b. malloc()
c. allocate
d. New
Answer: d

Which of the following operator is used to release the dynamically allocated memory in C++?
a. remove
b. free
c. delete
d. both b and c
Answer: c

Pick the odd one out


a) array type
b) character type
c) boolean type
d) integer type
Answer:a

Which type is best suited to represent the logical values?


a) integer
b) boolean
c) character
d) all of the mentioned
Answer:b

Is bool a fundamental datatype in C++?


a) Yes
b) No, it is a typedef of unsigned char
c) No, it is an enum of {false,true}
d) No, it is expanded from macros
Answer:a

What is the output of this program?


#include <iostream>
using namespace std;
enum cat {
temp = 7
};
int main()
{
int age = 14;
age /= temp;
cout << "If you were cat, you would be " << age << endl;
return 0;
}
a) If you were cat, you would be 5
b) If you were cat, you would be 2
c) If you were cat, you would be 7
d) none of the mentioned
Answer:b

What is the output of this program?


#include <iostream>
using namespace std;
enum test {
A = 32, B, C
};
int main()
{
cout << A << B<< C;
return 0;
}
a) 323334
b) 323232
c) 323130
d) none of the mentioned
Answer:a

What does your class can hold?


a) data
b) functions
c) both a & b
d) none of the mentioned
Answer:C

What is the output of this program?


#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
a) a:4 b:7
b) a:10 b:4
c) a:4 b:10
d) None of the mentioned
Answer:a

If an array is declared as
int a[5] = {3, 0, 1, 2}, then values assigned to a[0] & a[4] will be ________
#include<iostream>
using namespace std;
int main()
{ int a[5] ={3,0,1,2};
cout<<a[0];
cout<<a[4];
return 0;
}
A) 32
B) 02
C) 30
D) 04
Ans: C) 30

If the variable count exceeds 100, a single statement that prints “Too many” is
(A) if (count<100) cout<< “Too many”;
(B) if (count>100) cout>> “Too many”;
(C) if (count>100) cout<< “Too many”;
(D) None of these.

Ans: C

What will be output of following program


#include <iostream>
using namespace std;
main()
{
double a = 21.09399;
float b = 10.20;
int c ,d;
c = (int) a;
d = (int) b;
cout <<c <<' '<<d;
return 0;
}
A) 20 10
B) 10 21
C) 21 10
D) None
Ans: C

In this code what will be the value of total and sum?

float total = 100;

float & sum = total;

total = total +10;

cout<< total;

cout<< sum;

A) total =100 and sum = 110

B) sum = 110, total = 100

C) Both will print 110

D) This code is wrong

Ans: C

What is the output of following program ?


#include<iostream>
using namespace std;
inti=10;
int main ( )
{
inti=20;
{
inti=30.;
cout<<i<< :: i ;
}
return 0;
}
A- 3010
B- 3020
C- will result in a run time error
D. none of the above

Answer: A

Consider the following statements:


#include<iostream>
using namespace std;
int main()
{
int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
cout<<x;
return 0;
}
What will be the value of x after executing these statements?

a. 22
b.37
c.7
d. Error. Cannot be executed
Answer: B

What would be the output of the following program?


#include<iostream>
using namespace std;
int main()
{
int x,y=10,z=10;
x=(y==z);
cout<<x;
return 0;
}

a. 1
b. 0
c. 10
d. error
Answer: a
What will be the output of following program?
#include<iostream>
using namespace std;
int main()
{
float x;
x=(float)9/2;
cout<<x;
return 0;
}

a. 4.5
b. 4.0
c. 4
d. 5
Answer: a
OOP MCQ Unit-II

A class is a user defined data type which binds data and its associated functions together. Data
and member functions can be labeled by access specifiers as private, protected and public.

Example: Student

class Student
{
int age; //data is age and by default it is labeled by access specifier private
public:
void display() //display function labeled as public
{
}
return 0; //needed
}; //semicolon is needed to represent end of class

How to create object of student class


Student stud; //here stud is object of class Student , we can also create array of object ie stud[10]

class Student
int age;

void display()

Object stud created from Student class is given below

object stud

int age;

Whenever object gets created it gets only memory for data allocation while Function memory is
comman for all objects

Memory in a C/C++/Java program can either be allocated on a stack or a heap. Stack is


temporary memory while heap memory is allocated during the execution of instructions written
by programmers.

Static data member: Only one copy of that member is created for the entire class and is
shared by all the objects of that class, no matter how many objects are created.
Constructor is a method used to initialize the state of an object, and it gets invoked at the time of
object creation. Rules for constructor are: Constructor Name should be same as class name.
Constructor must have no return type.

Destructor is a method which is automatically called when the object is made of scope or
destroyed. Destructor name is also same as class name but with the tilde symbol before the name.

Types of Constructor: Default Constructor, Parameterized Constructor, Copy Constructor,


Constructor with default arguments

Default Constructor: If programmer provides a constructor for the class without parameter
explicitly that is called default constructor.

Parameterized Constructor: If programmer provides a constructor for the class without parameter
explicitly that is called default Parameter less constructor.

Copy Constructor: A copy constructor is a member function that initializes an object using
another object of the same class. A copy constructor has the following general function
prototype: ClassName (const ClassName &old_obj);

Multiple Constructors in a Class :


C + + permits to use more than one constructors in a single class.
Example:
Add( ) ; // No arguments
Add (int, int) ; // Two argument
The first constructor receives no arguments.
The second constructor receives two integer arguments.
The third constructor receives one add object as an argument.
Add a1;

MCQ :

Which of the following is correct?


a) C++ allows static type checking
b) C++ allows dynamic type checking.
c) C++ allows static member function to be of type const.
d) C++ allows both static and dynamic type checking
Answer: D
Which of the following term is used for a function defined inside a class?
A.Member Variable
B.Member function
C.Class function
D.Classic function
Answer: B

Classes are useful because they


[A] are removed from memory when not in use
[B] permit data to be hidden from other classes
[C] bring together all aspects of an entity in one place
[D] can closely model objects in the real world
Answer: B

Which of the following is true?


(A) Class is created from objects
(B) Objects of a class do not share non-static members. Every object has its own copy.
(C) Objects of a class do not share codes of non-static methods, they have their own copy
(D) None of the above
Answer: B

Which member function of class cannot modify its objects attributes ?


[A] friend functions
[B] Private member functions
[C] Constant member functions
[D] Static member functions
Answer: C

An expression A.B in C++ means ____


A) A is member of object B
B) B is member of Object A
C) Product of A and B
D) None of these
Answer: B
Data members and member functions of a class in C++ program are by default
A. protected
B. public
C. private
D. None of above

Answer : C

Which of the following statement is correct?


A. Class is an instance of object.
B. Object is an instance of a class.
C. Class is an instance of data type.
D. Object is an instance of data type.

Answer: B

The object can’t be ______


a. passed by reference
b. passed by value
c. passed by copy
d. passed as function
Answer d

When you create an object of a class A like A obj ; then which one will be called automatically
A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
Answer: A

Which of the following statements is correct?


A-Data items in a class must be private.
B-Both data and functions can be either private or public.
C-Member functions of a class must be private.
D-None of above
Answer: b

The static member functions __________________


a) Have access to all the members of a class
b) Have access to only constant members of a class
c) Have access to only the other static members (functions or variables) declared in the same
class)
d) None of above
Answ: c

In C++, there are three access specifiers_______


a. private , protected and public
b. constant , final , static
c. static , non-static and final
d. virtual, static and final
Answer: a

Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?
A-A class member and a class object.
B-A class object and a class.
C-A class and a member of that class.
D-A class object and a member of that class.
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

What happens if a class does not have a name?


a) It will not have a constructor
b) It will not have a destructor
c) It is not allowed
d) It will neither have a constructor or destructor
Answer:b

Constructor is a_______
A. class automatically called whenever a new object of this class is created
B. A class automatically called whenever a new object of this class is destroyed
C. A function automatically called whenever a new object of this class is created
D. A function automatically called whenever a new object of this class is destroyed

Answer: Option C
Which of the following is correct in C++?
a) Classes cannot have protected data members
b) Structures can have member functions
c) Class members are public by default
d) Structure members are private by default
Answer: b

Which of the following statement is correct?


A. A constructor is called at the time of declaration of an object.
B. A constructor is called at the time of use of an object.
C. A constructor is called at the time of declaration of a class.
D. A constructor is called at the time of use of a class.

Answer: A

Which of the following statements is correct about the constructors and destructors?
A. Destructors can take arguments but constructors cannot.
B. Constructors can take arguments but destructors cannot.
C. Destructors can be overloaded but constructors cannot be overloaded.
D. Constructors and destructors can both return a value.

Ans b

A constructor that accepts no parameter is called _____________


a. default constructor
b. parameterized constructors
c. copy constructor
d. None of above
Answer: a

The constructor which requires arguments to be provided is called ____________


a. default constructor
b. parameterized constructors
c. copy constructor
d. None of above
Answer: b

Which value will it take when both user and default values are given?
a) user value
b) default value
c) custom value
d) defined value
Answer: a

What is the role of destructors in Classes?


a) To modify the data whenever required
b) To destroy an object when the lifetime of an object ends
c) To initialize the data members of an object when it is created
d) To call private functions from the outer world
Answer: b

If we start our function call with default arguments means, what will be proceeding arguments?
a) user argument
b) empty arguments
c) default arguments
d) user & empty arguments
Answer: c

Which of the following is not a member of class?


Which of the following statement is correct?
A. Class is an instance of object.
B. Object is an instance of a class.
C. Class is an instance of data type.
D. Object is an instance of data type.
Answer: B

What does your class can hold?


A) Data
B) Functions
C) Both A & B
D) None of the above
Answer: C

Member function can be defined


a ) Outside the class definition
b) Inside the class definition
c) Both a & b
d) None of these
Answer: C

How many specifiers are present as access specifiers in a class in C++?


A) 1
B) 2
C) 3
D) 4
Answer: C

What will we not do with function pointers?


a) allocation of memory
b) deallocation of memory
c) both allocation & deallocation of memory
d) finds memory status
Answer: c

The fields in the class in c++ program are by default


A) protected
B) private
C) public
D) none of the mentioned
Answer: B

Which operator a pointer object of a class uses to access its data members and member
functions?
a) .
b) ->
c) :
d) ::
Answer: a

How the objects are self-referenced in a member function of that class.


a) Using a special keyword object
b) Using this pointer
c) Using * with the name of that object
d) By passing self as a parameter in the member function
Answer: b

Which of the following is correct?


a) Destructors can be virtual
b) There can be more than one destructor in a class
c) Destructor definition starts with !
d) Destructor is used to initialize objects
Answer: a
If different objects are created the separate memory space is created for ____.
A. data members
B. member functions
C. both A ans B
D. none of these
Answer: A

The memory required by any objects is dependent upon following factors


A. size of non static data members of the class
B. order of data members
C. Byte padding
D. all of these
Answer: D

Which of the following is correct way of declaring object of a class ?


A. Class_name object_name;
B. object_nameclass_name
C. class class_nameobject_name
D. class class_name object object_name
Answer: A

The constructors and destructors for objects are automatically invoked ____.
A. by making explicit call to constructor and destructor functions
B. when object enters and leaves its scope.
C. when inheritance occurs
D. none of these
Answer: B

Member functions of a class can be called


a ) Only by object of that class
b) Only by object of other class
c) By an object of any class
d) all of the above
Answer: a

A private member function can only be called by another function


a) that is a member of its class
b) that is a member of another class
c) that is a member of any class
d) by the object of that class
Answer: a
Choose the correct statement
a) Only data members are private
b) Only member functions are public
c) Both data & member functions can be public
d) The member functions are private
Answer: c

Inline functions are


a) declared in the class defined outside the class
b) defined outside the class using keyword inline
c) defined inside the class using keyword inline
d) none of the above
Answer: B

Which of the following keywords are used to control access to a class member?
a) default
b) break
c) protected
d) goto

Answer: c

Which of the following parameter passing mechanism is/are supported by C++ but not in C?
[A] Pass by value
[B] Pass by reference
[C] Pass by value result
[D] All of the above
Answer: B

A class cannot be ____________.


A. virtual
B. friend
C. generic
D. Inline
Answer: D

Which of the following is a valid inline function ‘myfun’?


A. inline voidmyfun {//function code}
B. void myfun() inline {//function code}
C. inline::void myfun{//function code}
D. none of these
Answer: A

Constructor and Destructor


A constructor function is ___________
a) A friend function to a class
b) A member function with the same name as its class
c) A non-member function
d) None of the above
Answer: B

A constructor function is generally defined ________________


a) In the public section of a class
b) In the private section of a class
c) In the protected section of a class
d) None of the above
Answer: a

A class having no public constructors is ____________


a) A private class
b) A public class
c) An abstract class
d) None of the above
Answer: a

If a constructor function is defined in private section of a class, then ________________


a) The object cannot be created
b) Only member functions and friends may declare objects of the class
c) Both (a) & (b)
d) None of the above
Answer: c

Given a class named Book, which of the following is not a valid constructor?
(A) Book ( ) { }
(B) Book ( Book b) { }
(C) Book ( Book&b) { }
(D) Book (char* author, char* title) { }
Answer: B

Which of the following statements regarding constructor is false?


a) A constructor may be defined static
b) Constructor can have default arguments
c) Member functions may be invoked from within a constructor
d) None of the above
Answer: a

Destructors are called _______________


a) in the same order of constructor calls
b) in the reverse order of constructor calls
c) in any random order
d) none of the above
Answer: B

If a default constructor is not defined then __________.


a) it will cause syntax error
b) it will cause runtime error
c) the complier will create constructor for creating an object
d) none of these
Answer: c

1How many constructors can a class have?


(A) 0
(B) 1
(C) 2
(D) any number
Answer: d

Which of the following is not the characteristic of constructor.


(A) They should be declared in the public section.
(B) They do not have return type.
(C) They can not be inherited.
(D) They can be virtual.
Answer: d

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

The destructor has the same name as the constructor, but is preceded by a
A - '~'
B - '-'
C - '^'
D - '::'
Answer: A

Which of the followings are true about constructors?


1. A class can have more than one constructor.
2. They can be inherited.
3. Their address can be referred.
4. Constructors cannot be declared in protected section of the class.
5. Constructors cannot return values.
a. Only 1,2,4
b. 1,2,4,5
c. 1,3,5
d. 1,4,5
Answer: D

Which of the following correctly declares an array of objects for a class ABC?
a) ABC array[10];
b) ABC array;
c) array{10};
d) array array[10];
Answer: A

Why separate memory locations are essential for an object

a) member variables hold different data values for different objects


b) each object in the class has separate member function
c) Both a,b
d) none of these
Answer: A

The amount of memory allocated for an object is equal to

a) amount of memory required by member functions of that class


b) amount of memory required by data members of that class
c) amount of memory required by both data members and data functions
d) amount of memory required by the class
Answer: B

All the objects of a class share the same copy of

a) data members
b) member functions
c) both data members and member function
d) None of these
Answer: B

What is the output of the following program?


#include<iostream>
using namespace std;
void swap(int m, int n) {
int x = m;

m = n;
n = x;
}
main() {
int x = 5, y = 3;
swap(x,y);
cout<<x<<" "<<y;
return 0;
}

A-35
B-53
C-55
D - Compile error

Answer: B

What is the output of following program?


#include <iostream>
using namespace std;
class rect
{
int x, y;
public:
void val (int, int);
int area ()
{
return (x * y);
}
};
void rect::val (int a, int b)
{
x = a;
y = b;
}
int main ()
{
rectrect;
rect.val (3, 4);
cout<< "rect area: " <<rect.area();
return 0;
}
a) Error
b) rect area: 12
c) rect area:24
d) none of the mentioned
Answer: b

What is the output of the following program?


#include <iostream>
using namespace std;
class Box
{
public :
double length;
double breadth;
double height;
};
int main( )
{
Box Box1;
double volume;
Box1.height = 5;
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout<< "Volume of Box1 : " << volume <<endl;
return 0;
}
a) "Volume of Box1 : " 213
b) Volume of Box1 : 213
c) Volume of Box1 : 215
d) Volume of Box1 : 217
Answer: B

What is the output of following code


#include <iostream>
using namespace std;

classabc
{
private:
int array1[5]={0,2,4,8,5};
public:
void compute();
};

voidabc ::compute()
{
int result=0;
for(inti=0;i<5;i++)
{
result=result+array1[i];
}
cout<< result;
}
int main()
{
abc x;
x.compute();
return 0;
}
a) 19
b) 20
c) Garbage value
d) Syntax error
Answer: a

What is the output of the following code?


What is the output of the following code?
#include<iostream>
using namespace std;
class test
{
int a,b;
public:
test(int x, int y)
{
a=x; b=y;
}
int sum();
void display();
};
int test::sum()
{
returna+b;
}
void test::display()
{
cout<<”\nThe result of addition is:”<<sum();
}
void main()
{
test obj1(7,9);
obj1.display();
return 0;
}
a. Error
b. The result of addition is:16
c. The result of addition is:sum();
d. The result of addition is:
Answer: B
OPERATOR OVERLOADING UNIT 3 MCQ

Polymorphism, a Greek term, means the ability to take more than one form. An operation may
exhibit different behavior is different instances. The behavior depends upon the types of data
used in the operation.
For example, consider the operation of addition. For two numbers, the operation will
generate a sum. If the operands are strings, then the operation would produce a third
string by concatenation. The process of making an operator to exhibit different behaviors
in different instances is known as operator overloading.

Overloaded operators are functions with special names: the keyword "operator" followed by the
symbol for the operator being defined. Like any other function, an overloaded operator has a
return type and a parameter list.

Box operator+(const Box&);

declares the addition operator that can be used to add two Box objects and returns final Box
object. Most overloaded operators may be defined as ordinary non-member functions or as class
member functions. In case we define above function as non-member function of a class then we
would have to pass two arguments for each operand as follows −
Box operator+(const Box&, const Box&);
Rules for Overloading Operators:
1. Only built-in operators can be overloaded. New operators can not be created.
2. Arity of the operators cannot be changed.
3. Precedence and associativity of the operators cannot be changed.
4. Overloaded operators cannot have default arguments except the function call operator ()
which can have default arguments.
5 .The overloaded operator must have at least one operand is of user defined type.
6.We cannot change the basic meaning of an operator. That is to say, we cannot redefine the
plus (+) operator to subtract one value from the other.
7.We cannot use friend functions to overload certain operators. The list is given below:

Assignment Operator =
Function call Operator ( )
Subscription Operator [ ]
Class member access operator ->
Except the operators specified, all other operators can be either member functions or a non
member functions.
8.Some operators like (assignment)=, (address)& and comma (,) are by default overloaded.
9.Unary operators, overloaded by means of a member function, take no explicit arguments and
return no explicit values, but, those overloaded by means of a friend function, take one
reference argument (the object of the relevant class).
10.Binary operator overloaded through a member function take one explicit argument and those
which are overloaded through a friend function take two explicit argument.
11.When using binary operators overloaded through a member function, the left hand operand
must be an object of relevant class.
12. Binary arithmetic operators such as +, -, * and / must explicitly return a value. They must not
attempt to change their own arguments

MCQ

What is operator overloading in C++?


a) Overriding the operator meaning by the user defined meaning for user defined data type
b) Redefining the way operator works for user defined types
c) Ability to provide the operators with some special meaning for user defined data type
d) All of the mentioned

Answer: d
Explanation: Operator overloading helps programmer to give his/her own meaning to an operator
for user defined data types (eg, classes).
Which is the correct statement about operator overloading in C++?.
A. Only arithmetic operators can be overloaded
B. Associativity and precedence of operators does not change
C. Precedence of operators are changed after overlaoding
D. Only non-arithmetic operators can be overloaded
Ans : B

Explanation: Both arithmetic and non-arithmetic operators can be overloaded. Priority and
affiliation of operators remain before and after operator overloading.

What is the syntax of overloading operator + which return int data type ?
a) int operator+(arguments){}
b) operator[+](argument_list){}
c) int +(argument_list){}
d) int [+](argument_list){}

Answer: a
Explanation: The general syntax for operator overloading is:
return_type operator OperatorSymbol(argument_list){}

Which of the following operators cannot be overloaded


(A) . (Member Access or Dot operator)
(B) ?: (Ternary or Conditional Operator )
(C) :: (Scope Resolution Operator)
(D) .* (Pointer-to-member Operator )
(E) All of the above

Answer: E

What is a binary operator?


a) Operator that performs its action on a single operand
b) Operator that performs its action on two operand
c) Operator that performs its action on three operand
d) Operator that performs its action on any number of operands

Answer: b
Explanation: As the word binary itself means 2 therefore a binary operator operates on two
operands.
Which is the correct example of a binary operator?
a) ++
b) —
c) Dereferencing operator(*)
d) +

Answer: d

Explanation: +(adding two operands) requires two operands whereas ++(increases value by 1), –
(decreases value by 1) and *(dereferencing operator used for accessing value of pointers)
requires only one operand.

Which is the correct example of a unary operator?


a) &
b) ==
c) —
d) /

Answer: c
Explanation: &, == and / requires two operands whereas — requires only one operand, in
general, it decreases the value of operand by 1.

Which is called ternary operator?


a) ?:
b) &&
c) |||
d) ===Answer: a
Explanation: ?: is called ternary operator because it separates three expressions. exp1 ? exp2 :
exp3.

Which is the correct statement about operator overloading?


a) Only arithmetic operators can be overloaded
b) Only non-arithmetic operators can be overloaded
c) Precedence of operators are changed after overlaoding
d) Associativity and precedence of operators does not change
Answer: d
Explanation: Both arithmetic and non-arithmetic operators can be overloaded. The precedence
and associativity of operators remains the same after and before operator overloading.

Pick the incorrect statements out of the following.


a) Operator overloading does not disturbs the precedence of operators
b) Arity of operators can be changed using operator overloading
c) No new operators can be created
d) All of the mentioned

Answer: b
Explanation: Arity means a number of operands an operator requires to perform its action and
operator overloading does not changes the arity of any operator.

Scope resolution operator is used______ .


a. to resolve the scope of global variables only
b. to resolve the scope of functions of the classes only
c. to resolve scope of global variables as well as functions of the classes
d. None of these
Answer: c

An operator function is created using _____________ keyword.


a. iterator
b. allocator
c. constructor
d. operator

Answer: d

Using friend operator function, following perfect set of operators may not be overloaded.
a. = , ( ) , [ ] , ->
b. <<, = = , [ ] , >>
c. ?, = , ( ) , ++
d. None of these
Answer: a
we can define a binary operator as :
A. The operator that performs its action on two operand
B. The operator that performs its action on three operand
C. The operator that performs its action on any number of operands

D. The operator that performs its action on a single operand

Answer: A

______ is not an operator overloaded by the C++ language.


A. <<
B. +
C. pow
D. >>

Answer : C

Ternary operator is shown as _____.


A. ===
B. &&
C. ?:
D. |||

Answer: C

In case of binary operator overloading with member function, which of following statement
should be taken into consideration?
a. Right hand operand must be object.
b. Left hand operand must be object.
c. Both the operands must be objects.
d. All of these should be considered.

Answer: b
While overloading unary operators using member function, it requires ___ argument?

A. 2
B. 1
C. 0
D. 3
Ans : C

While overloading binary operators using member function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
Ans : B

While overloading unary operators using friend function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
Ans : B

While overloading binary operators using friend function, it requires ___ argument?

A. 2
B. 1
C. 0
D. 3
Ans : A

What is a friend function in C++?


a) A function which can access all the private, protected and public members of a class
b) A function which is not allowed to access any member of any class
c) A function which is allowed to access public and protected members of a class
d) A function which is allowed to access only public members of a class
Answer: a
Explanation: Friend function in C++ is a function which can access all the private, protected and
public members of a class.
Which of the following is correct about friend functions?
a) Friend functions use the dot operator to access members of a class using class objects
b) Friend functions can be private or public
c) Friend cannot access the members of the class directly
d) All of the mentioned
Answer: d
Explanation: Friend function can be declared either in private or public part of the class. A friend
function cannot access the members of the class directly. They use the dot membership operator
with a member name.

Which keyword is used to declare the friend function?


a) firend
b) friend
c) classfriend
d) myfriend
Answer: b
Explanation: friend keyword is used to declare a friend function in C++.

A friend class can access ____________________ members of other class in which it is declared
as friend.

A. private
B. protected
C. public
D. Both A and B
Ans : D

Explanation: A friend class can access private and protected members of other class in which it is
declared as friend.

A friend function can be

A. A method of another class


B. A global function
C. Both A and B
D. None of the above

Ans : C

Explanation: A friend function can be:


a) A method of another class
b) A global function
If class A is a friend of B, then B doesn’t become a friend of A automatically.

A. TRUE
B. FALSE
C. Can be true and false
D. Can not say

Ans : A

Explanation: Friendship is not mutual. If class A is a friend of B, then B doesn’t become a friend
of A automatically.

Which of the following is correct about friend functions?

A. Friend functions use the dot operator to access members of a class using class objects
B. Friend functions can be private or public
C. Friend cannot access the members of the class directly
D. All of the above

Ans : D

Explanation: Friend function can be declared either in private or public part of the class. A friend
function cannot access the members of the class directly. They use the dot membership operator
with a member name.

Pick the correct statement.

A. Friend functions are in the scope of a class


B. Friend functions can be called using class objects
C. Friend functions can be invoked as a normal function
D. Friend functions can access only protected members not the private members
Ans : C

Explanation: Friend functions are not in the scope of a class and hence cannot be called through
a class object. A friend function can access all types of members of the class. They can be
invoked as a normal function.

Where does keyword ‘friend’ should be placed?


A. function declaration
B. function definition
C. main function
D. block function
Ans : A
Explanation: The keyword friend is placed only in the function declaration of the friend function
and not in the function definition because it is used toaccess the member of a class.

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) protected member can be accessed anywhere
d) private member can be accessed anywhere
Answer: a
Explanation: Friend is used to access private and protected members of a class from outside the
same class.

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
Explanation: A friend function may or may not be a member of another class is the correct
statement.

Where does keyword ‘friend’ should be placed?


a) function declaration
b) function definition
c) main function
d) block function
Answer: a
Explanation: The keyword friend is placed only in the function declaration of the friend function
and not in the function definition because it is used toaccess the member of a class.

Which of the following operators should be preferred to overload as a global function rather than
a member method?
A. Postfix ++
B. Comparison Operator
C. Insertion Operator <<
D. prefix ++
Ans : C
Explanation: Insertion Operator should be preferred to overload as a global function rather than a
member method.
Which of the following operators should be preferred to overload as a global function rather
than a member method?
(A) Postfix ++
(B) Comparison Operator
(C) Insertion Operator <<
(D) Prefix++
Answer: (C)

To implicitly overload the += operator:


A. Only the = operator needs to be overloaded.
B. Only the + operator needs to be overloaded.
C. The += operator cannot be overloaded implicitly.
D. Both the + and = operators need to be overloaded

Answer: C

Correct example of a binary operator is _______.


A. —
B. +
C. ++
D. Dereferencing operator(*)

Answer: B

How many approaches are used for operator overloading?


a) 1
b) 2
c) 3
d) 4

Answer: c
Explanation: There are 3 different approaches used for operator overloading:
i. Overloading unary operator.
ii. Overloading binary operator.
iii. Overloading binary operator using a friend function.
Which of the following operator cannot be overloaded?
a) +
b) ?:
c) –
d) %

Answer: b
Explanation: ?: , :: and . cannot be overloaded +, -, % can be overloaded.

Which of the following operator can be overloaded?


a) ?:
b) ::
c) .
d) ==

Answer: d
Explanation: ?:, :: and . cannot be overloaded whereas == can be overloaded.

Which of the following operator cannot be used to overload when that function is declared as
friend function?
a) -=
b) ||
c) ==
d) []

Answer: d
Explanation: When an operator overloaded function is declared as friend function then [] cannot
be overloaded.

Which of the following operator can be used to overload when that function is declared as friend
function?
a) []
b) ()
c) ->
d) |=

Answer: d
Explanation: When an operator overloaded function is declared as friend function then [], () and -
> cannot be overloaded.
OOP MCQs on Unit 4
Inheritance use is code reusability
Types: single, multiple ,multilevel, hierarchical , hybrid
Types of access specifiers : private, protected and public
scope of private variable : within base class only
protected variable : within base class and derived class,
public variable : through out program
static variable variable means comman memory of variable for all object
virtual keyword use to remove ambiguity in multiple inheritance

In above image, for Single Inheritance A is base class and B is derived class
For Multiple inheritance, A and B are base class and C is derived class
For multilevel inheritance, A is base class for derived class B and B is base class for
derived classC
For Hierarchical Inheritance, B, C and D are derived classes from Base class A
For Hybrid Inheritance, B and C are derived classes from Base class A and D is derived
class from Base class B and C ( So here hybrid inheritance is combination of Hierarchical
inheritance and Multiple inheritance )
TYPES OF INHERITANCE
1. In public inheritance of base class for derived class, all public members of base class
inherited as public in derived class, protected members of base class inherited as protected in
derived class and private members of base class inherited as private members in derived class
2. In protected inheritance of base class for derived class, all public members of base class
inherited as protected members in derived class , protected members of base class inherited as
protected members in derived class and private members of base class inherited as private
members in derived class
3. In private inheritance of base class for derived class, all public members of base class
inherited as private members in derived class, protected members of base class are inherited as
private members in derived class and private members of base class inherited as private members
in derived class

INHERITANCE SYNTAX EXAMPLE

Single Inheritance
class Child : public Parent
class B : public A
(here B is derived class and A is base class)

Multiple Inheritance
class Child : public Parent1, public Parent2
class C : public A, public B
(here C is derived class and A and B are base class)

MCQ

Which among the following best describes polymorphism?


a) It is the ability for a message/data to be processed in more than one form
b) It is the ability for a message/data to be processed in only 1 form
c) It is the ability for many messages/data to be processed in one way
d) It is the ability for undefined message/data to be processed in at least one way
Answer: a
Explanation: It is actually the ability for a message / data to be processed in more than one form.
The word polymorphism indicates many-forms. So if a single entity takes more than one form, it
is known as polymorphism.

C++ Inheritance relationship is


a) Association
b) Is-A
c) Has-A
d) None
Which of the following feature supports reusability and extensibility of classes?

a) Inheritance
b) Overloading
c) Polymorphism
d) None of the above

Inheritance is ………..in nature.


a) Intransitive
b) Transitive
c) Both (a) & (b)
d) None of the above

Inheritance allow in C++ Program?


a) Class Re-usability
b) Creating a hierarchy of classes
c) Extendibility
d) All

The derivation of Child class from Base class is indicated by ____ symbol.
A. ::
B. : (colon operator)
C. ;
D. |

When a derived class inherits only from one class and is not further inherited is
a) single inheritance
b) multiple inheritance
c) multilevel inheritance
d) hybrid inheritance

Class B is derived from class A then it is called____


A. single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance
When a derived class inherits from many base classes it is
a) multilevel inheritance
b) single inheritance
c) multiple inheritance
d) none of the above

Which among the following is best to define hierarchical inheritance?


a) More than one classes being derived from one class
b) More than 2 classes being derived from single base class
c) At most 2 classes being derived from single base class
d) At most 1 class derived from another class

Class C is derived from base class A and class B then it is called____


A. single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

The process of deriving a class from another derived class is


a) single inheritance
b) multilevel inheritance
c) multiple inheritance
d) none of the above

Class C is derived from class B and class B is derived from class A then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

The default visibility mode while inheriting is


a) private
b) public
c) protected
d) none of the above

Class D is derived from class Base1 and class Base2 then it is called ____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

Class B and C are derived from class A and class D is derived from class B and C, then it is
called _____.
A. Single inheritance
B. Multiple inheritance
C. Multilevel inheritance
D. Hybrid inheritance

What is meant by multiple inheritance?


a) Deriving a base class from derived class
b) Deriving a derived class from base class
c) Deriving a derived class from more than one base class
d) None of the mentioned

If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
(A) protected and public data only in C and B.
(B) protected and public data only in C.
(C) private data in A and B.
(D) protected data in A and B.

What does inheritance allows you to do?


A. create a class
B. create a hierarchy of classes
C. access methods
D. None of the mentioned

How many types of inheritance are there in c++?


A. 2
B. 3
C. 4
D. 5

//What will be the output of the following code?


#include <iostream>
using namespace std;
class A
{
public:
int x;
};
class B:public A //Single Inheritance
{
public:
void display()
{
x=10;
cout<<x;
}
};
int main()
{
B b; //b is object of Class B
b.display();
return 0;
}

a. 20
b. 10
c. 11
d. None of above
Answer: b

A virtual member function is member function that can


a. be overridden by a subclass
b. be derived from another class
c. move to any class
d. None of them

Which is the correct declaration of pure virtual function in C++


1. virtual void func = 0;
2. virtual void func() = 0;
3. virtual void func(){0};
4. void func() = 0;

C++ abstract class can contain


a) Pure virtual function
b) Non-virtual function
c) Only pure virtual function
d) Both pure virtual and non-virtual function

Which among the following best describes abstract classes?


a) If a class has more than one virtual function, it’s abstract class
b) If a class have only one pure virtual function, it’s abstract class
c) If a class has at least one pure virtual function, it’s abstract class
d) If a class has all the pure virtual functions only, then it’s abstract class
Answer: c
Explanation: The condition for a class to be called abstract class is that it must have at least one
pure virtual function.

If there is an abstract method in a class then, ________________


a) Class must be abstract class
b) Class may or may not be abstract class
c) Class is generic
d) Class must be public
Answer: a
Explanation: It is a rule that if a class have even one abstract method, it must be an abstract class.
If this rule was not made, the abstract methods would have got skipped to get defined in some
places which are undesirable with the idea of abstract class.

Following keyword is used before a function in a base class to be overridden in derived class in
C++
a) override
b) virtual
c) void
d) none

In case of inheritance where both base and derived class are having constructors, when an object
of derived class is created then___________
A. constructor of derived class will be invoked first
B. constructor of base class will be invoked first
C. constructor of derived class will be executed first followed by base class
D. constructor of base class will be executed first followed by derived class
Run time polymorphism is achieved only when a ……………….. Is accessed through a pointer
to the base class.
A) static function
B) Real function
C. Member function
D) Virtual function

Which concept is used to implement late binding?


a) Virtual functions
b) Operator functions
c) Constant functions
d) Static functions
Answer: a
Explanation: Virtual functions are used to implement the concept of late binding i.e. binding
actual functions to their calls.

Run time binding is related to


1. Function overriding
2. Operator overloading
3. A & B
4. None

In case of inheritance where both base and derived class are having constructor and destructor,
then which if the following are true ?
1. Constructors are executed in their order of derivation
2. Constructors are executed in reverse order of derivation
3. Destructors are executed in their order of derivation
4. Destructors are executed in reverse order of derivation
a. Only 2 ,4
b. Only 1 , 3
c. Only 1 , 4
d. Only 2, 3

What will be the order of execution of base class constructors in the following method of
inheritance class a: public b, public c {...};
A. b(); c(); a();
B. c(); b(); a();
C. a(); b(); c();
D. b(); a(); c();
Explain : here b and c are base class so their constructors will be executed first
Which of the following advantages we lose by using multiple inheritance?
A. Dynamic binding
B. Polymorphism
C. Both Dynamic binding & Polymorphism
D. None of the mentioned

A container class is a container whose instance are


a. containers
b. functions
c. Strings
d. None of them
Answer : a

Containers are having same types, that’s why they are called
a. Heterogeneous
b. Homogeneous
c. Vectors
d. None of them
Answer: b

In object-oriented programming, a singleton class is


a. a class that can have only one object (an instance of the class) at a time.
b. a class that can have multiple object (an instance of the class) at a time.
c. no object class
d. none of above
Answer : a

Which one of the following can’t be used for polymorphism?


A. Member functions overloading
B. Static member functions
C. global member function
D. Constructor overloading

Which among the following best defines static variables members?


a) Data which is allocated for each object separately
b) Data which is common to all the objects of a class
c) Data which is common to all the classes
d) Data which is common to a specific method
Answer: b
Explanation: The static data members are made common to all the object of a class. They doesn’t
change from object to object. Those are property of class rather than of any individual object.

Which keyword should be used to declare static variables?


a) static
b) stat
c) common
d) const
Answer: a
Explanation: The keyword used to declare static variables is static. This is must be used while
declaring the static variables. The compiler can make variables static if and only if they are
mentioned with static keyword.

Any changes made to static data member from one member function _____________
a) Is reflected to only the corresponding object
b) Is reflected to all the variables in a program
c) Is reflected to all the objects of that class
d) Is constant to that function only
Answer: c
Explanation: The changes made from any function to static data member will be a common
change for all the other objects also. If the change is made with respect to one object and change
is printed from another object, the result will be same.

Which among the following is correct definition for static member functions?
a) Functions created to allocate constant values to each object
b) Functions made to maintain single copy of member functions for all objects
c) Functions created to define the static members
d) Functions made to manipulate static programs
Answer: b
Explanation: The functions which are made common, with respect to definition and data usage,
to all the objects. These functions are able to access the static data members of a class.

The static member functions __________________


a) Have access to all the members of a class
b) Have access to only constant members of a class
c) Have access to only the static members of a class
d) Have direct access to all other class members also
Answer: c
Explanation: The static member functions are common for all the objects. These functions can
use only the static members of a class in which those are defined. This is because other members
change with respect to each object created.

The static member functions ____________________


a) Can be called using class name
b) Can be called using program name
c) Can be called directly
d) Can’t be called outside the function
Answer: a
Explanation: The static members can be accessed using class name also. This is because the
static members remain common to all the objects. Hence objects are not required.
Which is the pointer which denotes the object calling the member function?
a) Variable pointer
b) This pointer
c) Null pointer
d) Zero pointer
Answer: b
Explanation: The pointer which denotes the object calling the member function is known as this
pointer. The this pointer is usually used when there are members in the function with same name
as those of the class members.

Which among the following is true?


a) this pointer is passed implicitly when member functions are called
b) this pointer is passed explicitly when member functions are called
c) this pointer is passed with help of pointer member functions are called
d) this pointer is passed with help of void pointer member functions are called
Answer: a
Explanation: When an object calls some member function, it implicitly passes itself as an
argument. This allows the compiler to know which member should be used for the purposes.
This also allows to reduce the ambiguity among the variable and data member names.

The this pointer is accessible __________________


a) Within all the member functions of the class
b) Only within functions returning void
c) Only within non-static functions
d) Within the member functions with zero argument
Answer: c
Explanation: The this pointer is available only within the non-static member functions of a class.
If the member function is static, it will be common to all the objects and hence a single object
can’t refer to those functions independently.

What is purpose of Virtual destructor?

A. To maintain the call hierarchy of destructors of base and derived classes.


B. Destructor can be virtual so that we can override the destructor of base class in derived
class.
C. Virtual destructor is to destroy the VTable
D. None
Answer: A
Base class destructor is made virtual in inheritance relationship to maintain the call of destructors
in base and derived class. Note that first derived class destructor will be called then derived class.

In C++, virtual function is used in which concept?


A. function overloading
B. function overriding
C. constructor overloading
D. All of the above
Answer: B
Virtual functions are used in function overriding concept in inheritance relationship

Which of the following cannot be used with the virtual keyword?


a) Class
b) Member functions
c) Constructors
d) Destructors
Answer: c
Explanation: Virtual keyword cannot be used with constructors as constructors are defined to
initialized an object of particular class hence no other class needs constructor of other class.

If the base class is derived using protected mode then public members of the base class become
___ of derived class.
A. public members
B. private members
C. protected
D. none of these

If the base class is derived using protected mode then protected members of the base class
become ___ of derived class.
A. public members
B. private members
C. protected
D. none of these

What is the difference between protected and private access specifier?


A. private member is not inheritable and not accessible in derived class.
B. protected member is inheritable and also accessible in derived class.
C. both are inheritable but private is accessible inthe derived class.
D. both are inheritable but protected is not accessible in the derived class.

What is the syntax of inheritance of class?


A. class name
B. class name : access specifer
C. class name : access specifer class name
D. None of the mentioned

15. The process of building new classes from existing one is called
(A) Structure.
(B) Inheritance.
(C) Polymorphism.
(D) Template.
What is the difference between protected and private access specifiers in inheritance?
A. private member is not inheritable and not accessible in derived class.
B. protected member is inheritable and also accessible in derived class.
C. Both are inheritable but private is accessible in the derived class.
D. Both are inheritable but protected is not accessible in the derived class.

During a class inheritance in C++, if the visibility mode or mode of derivation is not provided,
then by default visibility mode is ___________.

A. public
B. protected
C. private
D. Friend

Which of the following is true?


(A) A “static” member of a class cannot be inherited by its derived class.

(B) A “static” member of a class can be initialized only within the class it is a member of.

(C) A “static” member of a class can be initialized before an object of that class is created.

(D) Since a “static” member of a class is actually a global element, it does not
require a class/object qualifier to access it independently of class/object.

Assume that we have constructor functions for both base class and derived class. Now
consider the declaration in
main()
Base *P=New Derived;
In what sequence will the constructor be called?

A. Derived class constructor followed by Base class constructor


B. Base class constructor followed by Derived class constructor
C. Base class constructor will not be called
D. Derived class constructor will not be called
If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access

A. only protected and public data of C and B


B. Only protected and public data of C
C. all data of C and private data of A and B
D. public and protected data of A and B and all data of C

Which of the following is/are correct with reference to Abstract class and interface?

a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neitehr a nor b are true

Which of the following is/are correct with reference to Abstract class and interface?

a. A class can inherit only one Abstract class but may inherit several interfaces
b. An abstract class can provide complete and default code but an interface has no code
A. a is true
B. b is true
C. Both a and b are true
D. Neither a nor b are true

Which of the following is used to make an Abstract class?

A. Making at least one member function as pure virtual function


B. Making at least one member function as virtual function
C. Declaring as Abstract class using virtual keyword
D. Declaring as Abstract class using static keyword

Which of the following differentiates between overloaded functions and overridden functions
?

A. Overloading is a dynamic or runtime binding and overridden is a static or compile


time binding.
B. Overloading is a static or compile time binding and overriding is dynamic
or runtime binding.
C. Redefining a function in a friend class is called overloading, while redefining a
function in a derived class is called as overridden function.
D. Redefining a function in a derived class is called function overloading, while
redefining a function in a friend class is called function overriding.

Interface class in C++ is created by


a) Using interface keyword before class
b) Using pure virtual function
c) Using pure virtual function and virtual function both
d) Using class keyword

When a class serves as base class for many derived classes, the situation is called:
a) polymorphism
b) hierarchical inheritance
c) hybrid inheritance
d) multiple inheritance

Which among the following can show polymorphism?


a) Overloading ||
b) Overloading +=
c) Overloading <<
d) Overloading &&

Which problem may arise if we use abstract class functions for polymorphism?
a) All classes are converted as abstract class
b) Derived class must be of abstract type
c) All the derived classes must implement the undefined functions
d) Derived classes can’t redefine the function

When the inheritance is private, the private methods in base class are __________ in the derived
class (in C++).
A. Inaccessible
B. Accessible
C. Protected
D. Public
What will be the output of the following code?
#include <iostream>
using namespace std;

class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
A. x=10,y=20,z=30
B. error for x,y=20,z=30
C. error for x and y,z=30
D. error for x,y and z
Explanation: here x , y are declared private so they are not accessible outside class A

What will be the output of the following code?


#include <iostream>
using namespace std;

class A
{
public:
A()
{
cout<<"base class constructor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class Constructor";
}
};
int main()
{
B b;
return 0;
}
A. base class constructor
B. base class constructor derived class constructor
C. base class constructorDerived class constructor
D. derived class constructor base class constructor

If 2 classes derive one base class and redefine a function of base class, also overload some
operators inside the class body. Among these two things of function and operator overloading,
where is polymorphism used?
a) Function overloading only
b) Operator overloading only
c) Both of these are using polymorphism
d) Either function overloading or operator overloading because polymorphism can be
applied only once in a program

What will be the output of the following code?


#include <iostream>
using namespace std;
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:public A
{
};
int main()
{
B b;
b.x=100;
cout<<b.x;
return 0;
}
A. 100
B. 0
C. syntax error
D. none of these
Answer: Syntax error as variable x is declared private, so not accessible outside class

What is the output of the following code?


class student
{
public :
int marks;
void disp()
{
cout<<”its base class”;
};
class topper:public student
{
public :
void disp()
{
cout<<”Its derived class”;
}
}
void main()
{
student s;
topper t;
s.disp();
t.disp();
}
A. its base class its derived class
B. its base class its derived class
C. its derived class it’s base class
D. none of these

Predict the output of following code:


#include<iostream>
using namespace std;
class P {
public:
void print() { cout <<" Inside P"; }
};
class Q : public P {
public:
void print() { cout <<" Inside Q"; }
};
class R: public Q { };
int main(void)
{
R r;
r.print();
return 0;
}
(A) Inside P
(B) Inside Q
(C) Compiler Error: Ambiguous call to print()
(D) None of the above
UNIT 5 OOP MCQ

Templates (used for Generic programming)


C++ adds two new keywords to support templates: ‘template’ and ‘typename’. The
second keyword can always be replaced by keyword ‘class’.
Types of templates: class template and function template
Function template syntax

template<class identifier> declaration;


template<typename identifier> declaration;

Example:

template<typename T>
T max(T a, T b)
{ return a > b ? a : b; }

Class Template syntax

template <class T>

class className
{
... .. ...
public:
T var;
T someOperation(T arg);
... .. ...
};

Namespace:
A namespace is a declarative region that provides a scope to the identifiers (names of the
types, function, variables etc) inside it.
A namespace definition begins with the keyword namespace followed by the namespace name
as follows –
namespace namespace_name {
// code declarations
}
To call the namespace-enabled version of either function or variable, prepend (::) the
namespace name as follows –
name::code; // code could be variable or function.

Scope operator(::) is used in namespace syntax.


Namespace (cin and cout objects belong to std namespace)
Exception handling-try block catch block, and throw
Errors can be broadly categorized into two types. We will discuss them one by one.

1. Compile Time Errors


2. Run Time Errors
Compile Time Errors – Errors caught during compiled time is called Compile time errors.
Compile time errors include library reference, syntax error or incorrect class import.
Run Time Errors - They are also known as exceptions. An exception caught during run time
creates serious issues.
In C++, Error handling is done using three keywords:

 try
 catch
 throw
try – throw-catch
try block (contain set of statements where exception can occur)
throw − A program throws an exception when a problem shows up.
catch block: A program catches an exception with an exception handler at the place in a
program where you want to handle the problem. The catch keyword indicates the catching of an
exception.
Syntax
try
{
//code
throw parameter;
}
catch(exceptionname ex)
{
//code to handle exception
}

Stream classes in C++ to take input from keyboard and display output on screen

istream

ostream
The cin object in C++ is an object of class istream
The cout object in C++ is an object of class ostream
iostream is derived class from istream and ostream (thus it can use both cin and cout)

MCQ

What is a template?

A. A template is a formula for creating a generic class


B. A template is used to manipulate the class
C. A template is used for creating the attributes
D. None of the above

_________________are used for generic programming

a. Inheritance
b. Virtual Functions
c. templates
d. None of these

Which keyword can be used in template?


a) class
b) typename
c) both class & typename
d) function
Answer: c
Explanation: Both keywords can be used as shown below:
template <class T> function declaration;
template <typename T> function declaration;

What is the syntax of class template?


a) template <paramaters> class declaration
b) Template <paramaters> class declaration
c) temp <paramaters> class declaration
d) Temp <paramaters> class declaration
Answer: a
Explanation: Syntax involves template keyword followed by list of parameters in angular
brackets and then class declaration. As follows template <paramaters> class declaration;
How to declare a template?
a) tem
b) temp
c) template<>
d) temp()
Answer: c
Explanation: template<> syntax is used.
An example for calculating max of two ints, floats, doubles, or any other number type where T
indicates the type of the parameters passes.
template <typename T>
T max(T a, T b){
return a > b? a : b;
}

What is the validity of template parameters?


a) inside that block only
b) inside the class
c) whole program
d) inside the main class
Answer: a
Explanation: Template parameters are valid inside a block only i.e. they have
block scope.

Can we have overloading of the function templates?


a. Yes
b. No
c. May Be
d. Can't Say

Which operator is used to signify the namespace in c++?


A. conditional operator
B. ternary operator
C. scope operator
D. None of the mentioned

Identify the incorrect statement?


A. Namespace is used to mark the beginning of the program
B. Namespace is used to mark the beginning & end of the program
C. A namespace is used to separate the class, objects
D. All of the above

What is the use of Namespace?


A. To encapsulate the data
B. Encapsulate the data & structure a program into logical units
C. It is used to mark the beginning of the program
D. None of the above
What is the general syntax for accessing the namespace variable?
A. namespace::operator
B. namespace,operator
C. namespace#operator
D. namespace$operator

Which keyword is used to access the variable in the namespace?


A. using
B. dynamic
C. const
D. static

The code of statements which may cause abnormal termination of the program shown written
under_________ block.
a. try
b. catch
c. finally
d. None of these

Which keyword is used to handle the exception?


A. try
B. throw
C. catch
D. None of the above

Which is used to throw a exception?


A. try
B. throw
C. catch
D. None of the above

Which exception is thrown by dynamic_cast?


A. bad_cast
B. bad_typeid
C. bad_exception
D. bad_alloc

How do define the user-defined exceptions?


A. Inherting & overriding exception class functionlity
B. Overriding class functionlity
C. Inherting class functionlity
D. None of the above

If inner catch handler is not able to handle the exception then__________ .


A. Compiler will look for outer try handler
B. Program terminates abnormally
C. Compiler will check for appropriate catch handler of outer try block
D. None of the above
Which type of program is recommended to include in try block?
A. Static memory allocation
B. Dynamic memory allocation
C. Const reference
D. Pointer

Which of the following statements are true about Catch handler?


1. It must be placed immediately after try block T.
2. It can have multiple parameters.
3. There must be only one catch handler for every try block.
4. There can be multiple catch handler for a try block T.
5. Generic catch handler can be placed anywhere after try block.

a. Only 1, 4, 5
b. Only 1, 2, 3
c. Only 1, 4
d. Only 1, 2

Exception handlers are declared with ____________ keyword.


a. Try
b. catch
c. throw
d. Finally

An exception is thrown using _____________ keyword in CPP.


a. throws
b. throw
c. threw
d. Thrown

In nested try block, if inner catch handler gets executed, then __________?
A. Program execution stops immediately.
B. Outer catch handler will also get executed.
C. Compiler will jump to the outer catch handler and then executes remaining executable
statements of main().
D. Compiler will execute remaining executable statements of outer try block and then
the main().

Return type of uncaught_exception() is ___________.


A. int
B. bool
C. char *
D. double
Templates are abstract recipe for producing a concrete code, and it is used for

A. Producing functions
B. Producing classes
C. Nothing
D. Both A and B

From where does the template class derived?


A. Regular non-templated C++ class
B. Templated class
C. Both A or B
D. None of the above

Can we have overloading of the function templates?


A. Yes
B. No
C. May Be
D. Can't Say

How many parameters are legal for non-type template?

A. 1
B. 2
C. 3
D. 4

How many kinds of entities are directly parameterized in c++?


A. 1
B. 2
C. 3
D. 4
Answer: c
Explanation: C++ allows us to parameterize directly three kinds of entities through templates:
types, constants, and templates.

Which of the things does not require instantiation?


A. Functions
B. Non virtual member function
C. Member class
D. All of the above

The use of Namespace is to structure a program into logical units?


A. TRUE
B. FALSE
C. May Be
D. Can't Say
Which of the following statements are true about Catch handler?
i) It must be place immediately after try block T.
ii) It can have multiple parameters.
iii) There must be one catch handler for every try block
iv) There can be multiple catch handler for a single try block T.
v) Generic catch handler can be placed anywhere after try block.

A. Only i, iv, v
B. Only i, ii, iii
C. Only i, iv
D. Only i, ii

Templates are abstract recipe for producing a concrete code, and it is used for
a. Producing functions
b. Producing classes
c. Nothing
d. Both A and B

From where does the template class derived?


a. Regular non-templated C++ class
b Templated class
c. Both A or B
d. None of the above

Which of the things does not require instantiation?


A. Functions
B. Non virtual member function
C. Member class
D. All of the above

Pick the incorrect statement for namespaces in C++.


a) Namespace declarations are always global scope
b) Keyword namespace is used at the starting of a namespace definition
c) Namespace has access specifiers like private or public
d) Namespace definitions can be nested

What is meant by exception specification?


a) A function is limited to throwing only a specified list of exceptions
b) A catch can catch all types of exceptions
c) A function can throw any type of exceptions
d) A try can catch all types of exceptions

What will happen when a programs throws any other type of exception other than
specified?
a) terminate
b)arise error
c)run
d)throw

What is meant by the template parameter?


a) It can be used to pass a type as an argument
b) It can be used to evaluate a type
c) It can of no return type
d) It can be used to delete a type
What is the use of Namespace?
a) To encapsulate the data
b) To structure a program into logical units
c) Encapsulate the data & structure a program into logical units
d) It is used to mark the beginning of the program

Which keyword is used to access the variable in the namespace?


a)using
b)static
c) dynamic
d)const

Which operator is used for accessing a member of namespace?


a).
b)::
c)->
d)&
Answer: b

Can we have overloading of the function templates?


a)Yes
b)No
c)Maybe
d)None of the above

Identify the incorrect statement?


a) Namespace is used to mark the beginning of the program
b) A namespace is used to separate the class, objects
c)All of the above
d) None of the above

Which operator is used to signify the namespace in c++?

a) conditional operator
b) ternary operator
c) scope operator
d) None of the mentioned

Identify the incorrect statement?

a). Namespace is used to mark the beginning of the program


b). Namespace is used to mark the beginning & end of the program
c) A namespace is used to separate the class, objects
d) All of the above

What is the use of Namespace?


a). To encapsulate the data
b) Encapsulate the data & structure a program into logical units
c) It is used to mark the beginning of the program
d) None of the above
What is the general syntax for accessing the namespace variable?

a) namespace::operator
b) namespace,operator
c) namespace#operator
d) namespace$operator

Which value is placed in the base class?


A. Derived values
B. Default type values
C. Both default type & derived values
D. None of the above

What is an exception in C++ program?


a) A problem that arises during the execution of a program
b) A problem that arises during compilation
c) Also known as the syntax error
d) Also known as semantic error

Answer: a
Explanation: An exception is defined as the problem in C++ program that arises during the
execution of the program for example divide by zero error.

What is the advantage of exception handling ?


1. Remove error-handling code from the software's main line of code.
2. A method writer can chose to handle certain exceptions and delegate others to the caller.
3. An exception that occurs in a function can be handled anywhere in the function call stack.
(A) Only 1
(B) 1, 2 and 3
(C) 1 and 3
(D) 1 and 2
Answer: B

Explanation: Advantage of exception handling are :-


1. Remove error-handling code from the software’s main line of code.
2. A method writer can chose to handle certain exceptions and delegate others to the caller.
3. An exception that occurs in a function can be handled anywhere in the function call
stack.
4. Separating Error-Handling Code from “Regular” Code.
5. Propagating Errors Up the Call Stack.

By default, what a program does when it detects an exception?


a) Continue running
b) Results in the termination of the program
c) Calls other functions of the program
d) Removes the exception and tells the programmer about an exception
Answer: b
Explanation: By default, whenever a program detects an exception the program crashes as it
does not know how to handle it hence results in the termination of the program.
Why do we need to handle exceptions?
a) To avoid unexpected behaviour of a program during run-time
b) To let compiler remove all exceptions by itself
c) To successfully compile the program
d) To get correct output
Answer: a
Explanation: We need to handle exceptions in a program to avoid any unexpected behaviour
during run-time because that behaviour may affect other parts of the program. Also, an
exception is detected during run-time, therefore, a program may compile successfully even with
some exceptions cases in your program.

Which is used to handle the exceptions in c++?


a) catch handler
b) handler
c) exception handler
d) throw
Answer: c
Explanation: Exception handler is used to handle the exceptions in c++.

Which statement is used to catch all types of exceptions?


a) catch()
b) catch(Test t)
c) catch(…)
d) catch(Test)
Answer:c
Explanation: This catch statement will catch all types of exceptions that arises in the program.

How to print the value of the i variable inside namespace B?


namespace A
{

int var = 10;

namespace B
{

int i = 15;

}
}
a) cout<<A::i;
b) cout<<B::i;
c) cout<<A::B::i;
d) cout<<i;
What will be the output of the following C++ code?
#include <iostream>
#include <typeinfo>
using namespace std;
class Polymorphic {virtual void Member(){}};
int main ()
{
try
{
Polymorphic * pb = 0;
typeid(*pb);
}
catch (exception& e)
{
cerr << "exception caught: " << e.what() << endl;
}
return 0;
}

a) exception caught: std::bad_typeid


b) exception caught: std::bad_alloc
c) exception caught: std::bad_cast
d) exception caught: std::bad_id

An exception may arise when _______________


a) Input is fixed
b) Input is some constant value of program
c) Input given is invalid
d) Input is valid
Answer:c
Explanation: The exceptions may arise because the input given by the user might not be of the
same type that a program can manage. If the input is invalid the program gets terminated.

C++ uses <iostream.h> directive because


A. C++ is object oriented language
B. C++ is a markup language
C. C++ does not have any input/output facility
D. All of them
Answer: C

The unformatted input functions are handled by


A. ostream class
B. instream class
C. istream class
D. bufstream class
Answer: C
Which of the following is correct option?
#include<iostream>
using namespace std;
namespace lfc1
{
int var = 30;
}
namespace lfc2
{
double var = 13.5478;
}
int main ()
{
int a;
a = lfc1::var + lfc2::var;
cout << a;
return 0;
}
a)43.54
b)43
c)44
d)30

What is the output of this program?


#include <iostream>
using namespace std;

int main()
{
try
{
throw 'b';
}
catch (int param)
{
cout << "Int Exception";
}
catch (...)
{
cout << "Default Exception";
}
cout << "After Exception";
return 0;
}
a) Default Exception After Exception
b) Int Exception After Exception
c) Int Exception
d) Default Exception
What may be the name of the parameter that the template should take?
a) same as template
b) same as class
c) same as function
d) same as member
Answer: a
Explanation: The name of the parameter that the template should take same as the template.

Which of the following best defines the syntax for template function ?
A. template return_type Function_Name(Parameters)
B. template return_type Function_Name(Parameters)
C. Both A and B
D. None of the above

How many template parameters are allowed in template classes?


a) 1
b) 2
c) 3
d) one or more
Answer: d
Explanation: Just like normal parameters we can pass more than one or more template
parameters to a template class.
OOP Unit 6 MCQ

A C++ stream is a flow of data into or out of a program


ifstream class-to read files on harddisk/floppy disk etc
ofstream class-to write files on harddisk/floppy disk etc (ios::out default mode)
fstream class- to do both read and write input/output (io) operations on files on harddisk/floppy
disk etc (both io opeartions)
fstream is derived class base class from ifstream and ofstream thus can perform both input and
output operations on files (read and write files on harddisk) ie it can access all public
functionalities of ifstream and ofstream

files open by default in txt mode


open method and constructor to open any file ( return type of open method is bool)
close method to close any file

FIle is structure and *ptr is pointer to file and tell_p() to get current position of file pointer in
file
eof() You can detect when the end of the file is reached by using the member function eof() which
has prototype : int eof(); It returns non-zero when the end of file has been reached, otherwise it
returns zero.
fseek() is used to move file pointer associated with a given file to a specific position
rewind() to set position to beginning and no way to check if the operations completed
successfully
ios::ate to open a file for output and move the read/write control to the end of the file
The ferror() function checks for any error in the stream. It returns a value zero if no error has
occurred and a non-zero value if there is an error. The error indication will last until the file is
closed unless it is cleared by the clearerr() function.
FILE READ/WRITE
Examples: lets say we want to read data from .txt file located on harddisk
So we can use command
ifstream fin ; //here we are creating fin as object of ifstream
// above read file using function open and by default open mode = ios::in mode

fin.open("sample.txt");

lets say we want to write data from .txt file located on harddisk
ofstream fout; //fout is object of stream class ofstream
// by default ios::out mode, automatically deletes
fout.open("sample.txt"); //write using open method

To close file

fin.close();

FILE MODES

Example :
Example of opening/creating a file using the open() function

#include<iostream>
#include <fstream>
using namespace std;
int main()
{
fstream new_file; //new_file is object of fstream
new_file.open("test.txt",ios::out); //open method to open file in out mode
if(!new_file)
{
cout<<"File creation failed";
}
else
{
cout<<"New file created";
new_file.close(); // Step 4: Closing file
}
return 0;
}

//In above example, file test.txt is open in with showing different modes of operation

FILE POINTERS IN CPP


MCQ
Object Oriented Programming
By default, all the files in C++ are opened in _________ mode.
a) Text
b) Binary
c) ISCII
d) VTC
Answer: a
Explanation: By default, all the files in C++ are opened in text mode. They read the file as normal
text.

Which header file is required to use file I/O operations?


a) <ifstream>
b) <ostream>
c) <fstream>
d) <iostream>
Answer: c

Which of the following is used to create a stream that performs both input and output operations?
a) ofstream
b) ifstream
c) iostream
d) fstream
Answer:d
Explanation: fstream is used to create a stream that performs both input and output operations in C++
file handling.

Which of the following is used to create an output stream?


a) ofstream
b) ifstream
c) iostream
d) fsstream
Answer: a
Explanation: ofstream is used to create an output stream in C++ file handling operations.

What is the return type open() method?


a) int
b) char
c) bool
d) float
Answer : c

Which function is used in C++ to get the current position of file pointer in a file?
a) tell_p()
b) get_pos()
c) get_p()
d) tell_pos()

Which of these is the correct statement about eof() ?


A. Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.

The purpose of a file buffer is:


A. to use memory
B. to speed up input/output
C. to speed up arithmetic operations
D. to protect data

6. ofstream, ifstream, and fstream are:


A. libraries
B. header files
C. built in classes
D. string arrays

Which member function is used to determine whether the stream object is currently associated with a
file?
A. is_open
B. Buf
C. String
D. None of the above

The __________ built in class can be used to create files and read information from them into
memory.
A. instream
B. ifstream
C. ofstream
D. istream

fseek() should be preferred over rewind() mainly because


A. In rewind, there is no way to check if the operations completed successfully
B. rewind() doesn't work for empty files
C. rewind() does work for empty file
D. All of the above

Which of the following true about FILE *fp


A. FILE is a structure and fp is a pointer to the structure of FILE type
B. FILE is a buffered stream
C. FILE is a keyword in C for representing files and fp is a variable of FILE type
D. FILE is a stream

When fopen() is not able to open a file, it returns


a. EOF
b. NULL
c. Runtime error
d. none of above
Answer: b
In fopen(), the open mode "wx" is sometimes preferred "w" because. i) Use of wx is more efficient.
ii) If w is used, old contents of file are erased and a new empty file is created. When wx is used,
fopen() returns NULL if file already exists.
A. Only i
B. Only ii
C. Both i & ii
D. None of the above

getc() returns EOF when?


a. End of file is reached
b. When getc() fails to read a character
c. both of above
d. none of above
Answer: c

To perform File I/O operations, we must use _____________ header file.


A. < ifstream>
B. < ofstream>
C. < fstream>
D. Any of these

How to get position to the nth byte of fileObject ?


A. fileObject.seekg( 'filename',n );
B. fileObject.seekg( n, 'filename' );
C. fileObject.seekg( n );
D. fileObject.seekg( n, ios::app );

What must be specified when we construct an object of class ostream?


A. stream
B. streambuf
C. memory
D. None of the mentioned

In order, the three-step process of using a file in a C++ program involves:


A. Name the file, open the file, and delete the file
B. Insert a diskette, open a file, and remove the disk
C. Open the existing file, read/write data, close the file
D. Create the file contents, close the file, and name the file

Which of the following is used to Open a file for output and move the read/write control to the end of
the file ?
A. ios::ate
B. ios::at
C. ios::ann
D. ios::end

What is the use of rewind() function in C?


A. set the position to the beginning point
B. gives current position in the file
C. set the position to desire point
D. None of these

What will be the output of this program?


using namespace std;
int main ()
{
FILE *fp;
char x[1024];
fp = fopen("find.txt", "r"); // "ayushjain and prateek"
x[0] = getc(fp);
fseek(fp, 0, SEEK_END);
fseek(fp, -7L, SEEK_CUR);
fgets(x, 6, fp);
puts(x);
return 0;
}
A. ayushj
B. yushja
C. ayushja
D. prate

Which of these is the correct statement about eof() ?

A. Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.
Answer: C

Which of the following is not used as a file opening mode?


a) ios::trunc
b) ios::binary
c) ios::in
d) ios::ate
Answer: a
Explanation: ios::trunc is used to truncate a file if it exists. It is not a file opening mode.

Which of the following statements are correct?

1) It is not possible to combine two or more file opening mode in open() method.
2) It is possible to combine two or more file opening mode in open() method.
3) ios::in and ios::out are input and output file opening mode respectively.

a) 1, 3
b) 2, 3
c) 3 only
d) 1, 2

Answer: a
Explanation: C++ allows to use one or more file opening mode in a single open() method. ios::in and
ios::out are input and output file opening mode respectively.
What is the use of ios::trunc mode?
a) To open a file in input mode
b) To open a file in output mode
c) To truncate an existing file to half
d) To truncate an existing file to zero
Answer: d
Explanation: In C++ file handling, ios::trunc mode is used to truncate an existing file to zero length.

Which of the following is the default mode of the opening using the ofstream class?
a) ios::in
b) ios::out
c) ios::app
d) ios::trunk
Answer: b
Explanation: By default, the file is opened in ios::out mode if the file object we are using is of
ofstream class.

Which stream class is to only write on files ?

A. ofstream
B. ifstream
C. fstream
D. iostream
Answer: a

Which operator is used to insert the data into file?

A. >>
B. <<
C. <
D. None of the above
Answer: b

which mode opens the file and sends outputs at the end______

a. app

b. in

c. out

d. trunk

Which of the following is the default mode of the opening using the ifstream class?
a) ios::in
b) ios::out
c) ios::app
d) ios::trunk

Answer: a
Explanation: By default, the file is opened in ios::in mode if the file object we are using is of ifstream
class.

Which of the following is not used to seek file pointer?


a) ios::set
b) ios::end
c) ios::cur
d) ios::beg

Answer: a
Explanation: ios::set is not used to seek file pointer. ios::end is used to seek from the end of the file.
ios::curr from the current position. ios::beg from the beginning.
The Shirpur Education Society’s
R. C. Patel Polytechnic, Shirpur [1808]
MCQ ON UNIT 3 INHERITANCE

Programme Code: CO Year/Scheme: Third/I Semester: THIRD

Course Title: Object Oriented Programming using C++ Course Abbr.: OOP Course Code: 22316

Number of questions: 50 Total Marks: Duration:

Instructions:
1. Attempt minimum 30 out of 40 questions.
2. Each question carries 01 mark.

1. How many types of inheritance are there in c++?


a 2 b 4
c 3 d 5
There are five types of inheritance in c++. They are single, Multiple, Hierarchical, Multilevel, Hybrid.

2. What is the syntax of inheritance of class?


a class name b class name : access specifer
c class name : access specifer class name d None of the mentioned

3. What does inheritance allows you to do?

a create a class b create a hierarchy of classes


c access methods d None of the mentioned

4. The ……………. inherits some or all of the properties of the ……….. class.
a base, derived b derived, base c derived, initial d base, final

5. A derived class with only one base class is called …………… inheritance.
a single b multiple c multilevel d hierarchical

6. A class can inherit properties from more than one class which is known as ……….inheritance.
a single b multiple
c multilevel d hierarchical

7. A class can be derived from another derived class which is known as ………. inheritance.
a single b multiple c multilevel d hierarchical

8. When a base class is privately inherited by a derived class public members of the base class
become ………. of the derived class.
a private members b protected c Public members d Not inherited
members

9. When a base class is privately inherited by derived class public members of the base class can

Sub. Code: 22316 Page 1 of 7


only be accessed by the ……… of the derived class.
a non-member b friend functions c member d class members
functions functions

10. Which symbol is used to create multiple inheritance?


a A. Dot b B. Comma
c C. Dollar d D. None of the above

11. When a protected member is inherited in public mode, it becomes ……….. in the derived class too
and therefore is accessible by member functions of the derived class.
a protected b private c public d friend

12. State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become members of its derived
class.
a True, False b False, True c True, True d False, False

13. A member declared as ………….. is accessible by the member functions within its class and any
class immediately derived from it.
a protected b private c public d friend

14. State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become members of its derived
class.
a True, False b False, True c True, True d False, False

15. A member declared as ………….. is accessible by the member functions within its class and any
class immediately derived from it.
a protected b private c public d friend

16. When the base class is publicly inherited, public members of the base class become …………. of
the derived class.
a private members b protected c Public members d Not inherited
members

17. In the protected derivation, both the public and protected members of the base class become
…………. members of the derived class.
a protected b private c public d friend

18. What will be the order of execution of base class constructors in the following method of
inheritance?
class A: public B, public C {….};
a A) B(); C(); A(); b B) C(); B(); A(); c C) A(); B(); C(); d D) B(); A(); C();

19. What will be the order of execution of base class constructors in the following method of
inheritance?
class A: public B, virtual public C {….};
a B(); C(); A(); b C(); B(); A(); c A(); B(); C(); d B(); A(); C();

Sub. Code: 22316 Page 2 of 7


20. While the friend functions and the member functions of a friend class can have direct access to
both the private and protected data, the member functions of a derived class can directly access
only the ………… data.
a protected b private c public d friend

21. What is the output of this program?

a Executed
b Error
c Runtime error
d None of the mentioned

22. In ……………………. inheritance, the constructors are executed in the order of inheritance.
a multipath b multiple c multilevel d hierarchical

23. The member functions of a derived class can directly access only the ……………….. data.
a private and protected b private and public
c protected and public d private, protected and public

24. The friend functions and the member functions of a friend class can directly access the
………………. data.
a private and protected b private and public
c protected and public d private, protected and public

25. When the inheritance is private, the private methods in base class are __________ in the derived
class (in C++).
a Inaccessible b Accessible
c Protected d Public

26. In ……………….. inheritance, the base classes are constructed in the order in which they appear in
the deceleration of the derived class.
a multipath b multiple c multilevel d hierarchical

27. ……………….. inheritance may lead to duplication of inherited members from a ‘grandparent’ base
class.
a multipath b multiple c multilevel d hierarchical

28. What is meant by multiple inheritance?


a Deriving a base class from derived class
b Deriving a derived class from base class
c Deriving a derived class from more than one base class
Sub. Code: 22316 Page 3 of 7
d None of the mentioned

29. Inheritance allow in C++ Program?


a Class Re-usability b Creating a c Extendibility d All of the above
hierarchy of
classes

30. What will be the output of the following program?

a In find
b In course
c Compiler Error: Ambiguous call to print()
d None of the above

31. What is the output of this program?

a Compiler Dependent b Base1 Base2 Derived


c Base2 Base1 Derived d Compiler Error

32. Which of the following is true about the following program

Sub. Code: 22316 Page 4 of 7


a Base1 Base2 Derived
b Derived Base2 Base1
c Derived
d Compiler Dependent

33. ___________ inheritance may lead to duplication of inherited members from a "grandparent" base
class.
a Multipath b Multiple c Multilevel d Hierarchical

34. Which of the following can be facilitated by the Inheritance mechanism?


1. Use the existing functionality of base class.
2. Overrride the existing functionality of base class.
3. Implement new functionality in the derived class.
4. Implement polymorphic behaviour.
5. Implement containership.
a 1, 2, 3
b 3, 4
c 2, 4, 5
d 3, 5

35.

36. Which inheritance type is used in the class given below?


class A : public X, public Y
{
}
a Multilevel b Multiple c Hybrid d Hierarchical

37. Which inheritance type is used in the class given below?


class A : public B
{
}
a Multilevel b Multiple c Hybrid d Single

Sub. Code: 22316 Page 5 of 7


38. Which inheritance type is used in the class given below?
class A
{
... .. ...
};
class B: public A
{
... .. ...
};
class C: public B
{
... ... ...
};
a Multilevel b Multiple c Hybrid d Hierarchical

39. Which inheritance type is used in the class given below?


class base_class {
... .. ...
}

class first_derived_class: public base_class {


... .. ...
}

class second_derived_class: public base_class {


... .. ...
}

class third_derived_class: public base_class {


... .. ...
}
a Multilevel b Multiple c Hybrid d Hierarchical

40. Which inheritance type is used in the class given below?

class A
{
.........
};
class B : public A
{
..........
};
class C
{
...........
};
class D : public B, public C
{
...........
};

Sub. Code: 22316 Page 6 of 7


a Multilevel b Multiple c Hybrid d Hierarchical

41. Which of the following is an invalid visibility label while inheriting a class
a public b private c protected d friend

40.
a b c d

41.
a b

40.
a b c d

41.
a b

40.
a b c d

41.
a b

https://www.siteforinfotech.com/2017/05/top-20-mcq-questions-inheritance-in-cpp.html

Sub. Code: 22316 Page 7 of 7


UNIT-1

1.What is the size of wchar_t in C++?

A. 2

B. 4

C. 2 or 4

D. based on the number of bits in the system

ANSWER: A

2.Pick the odd one out

A. array type

B. character type

C. boolean type

D. integer type

ANSWER: A

3.Which datatype is used to represent the absence of parameters?

A. int

B. short

C. void

D. float

ANSWER: C

4.What does a escape code represent?

A. alert

B. backslash

C. tab

D. form feed

ANSWER: B

5.Which type is best suited to represent the logical values?

A. integer
B. boolean

C. character

D. all of the mentioned

ANSWER: B

6.Identify the user-defined types from the following?

A. enumeration

B. classes

C. both a and b

D. int

ANSWER: C

7.Which of the following statements are true? int f(float)

A. f is a function taking an argument of type int and retruning a floating point number

B. f is a function taking an argument of type float and returning a integer.

C. f is a function of type float

D. none of the mentioned

ANSWER: B

8.The value 132.54 can represented using which data type?

A. double

B. void

C. int

D. bool

ANSWER: A

9.When a language has the capability to produce new data type mean, it can be called as

A. overloaded

B. extensible

C. encapsulated

D. reprehensible
ANSWER: B

10.Pick the odd one out.

A. integer, character, boolean, floating

B. enumeration, classes

C. integer, enum, void

D. arrays, pointer, classes

ANSWER: C

11.<< is called

A. Insertion operator

B. Extraction operator

C. Object

D. Function

ANSWER: A

12.>> is called

A. Insertion operator

B. Extraction operator

C. Object

D. Function

ANSWER: B

13.cin object in c++ corresponds to the

A. standard input stream

B. standard output stream

C. Iterative statement

D. Function
ANSWER: A

14.The for loop is best if we know

A. Fixed number of iterations

B. Test condition

C. Value for calculation

D. Number of conditions are fixed

ANSWER: A

15.In while loop condition is evaluated

A. First then body is executed

B. After the execution of body

C. In between the body of the loop

D. After update statement is executed

ANSWER: A

16.In do__while loop the condition is evaluated

A. First then body is executed

B. After the execution of body

C. In between the body of the loop

D. After update statement is executed

ANSWER: B

17.To display output; what is used in C++

A. cout

B. cin

C. header file

D. class
ANSWER: A

18. Function prototype is also called

A. Function declaration

B. Function definition

C. Function call

D. Return type

ANSWER: A

19.Inline function should be used

A. Small set of code

B. Large set of code

C. Friend function

D. For main() function

ANSWER: A

20.Static variable should be defined

A. Inside the function

B. Outside the function

C. In the function call

D. Anywhere

ANSWER: B

21.Parameters associated with function call are called

A. Actual parameter

B. Formal parameter

C. Global parameter

D. Auto parameter
ANSWER: A

22.Parameters defined within the function are

A. Extern parameter

B. Formal parameter

C. Auto parameter

D. Register parameter

ANSWER: B

23.Which storage specifiers retains the value between the function call

A. Auto

B. Register

C. Extern

D. Static

ANSWER: D

24.If function does not return any value then its return type is

A. Int

B. Float

C. Void

D. Char

ANSWER: C

25.Maximum number of values that can be returned by any function

A. 1

B. 2

C. 0

D. 4
ANSWER: A

26.Lifetime of extern variable is

A. Function

B. File

C. Block

C. None

ANSWER: B

27.Which method of parameter passing does not change the original variable

A. Call by value

B. Call by reference

C. Call by pointers

D. Both b and c

ANSWER: A

28.C++ was originally developed by;

A. Clocksin and Mellish

B. Donald E. Knuth

C. Sir Richard Hadlee

D. Bjame Stroustrup

ANSWER: D

29.cfront

A. is the front end of a C compiler

B. is the pre-processor of a C compiler

C. is a tool that translates a C++ code to its equivalent C code

D. none of the above


ANSWER: C

30.Which of the followinig are procedural languages?

A. Pascal

B. Smalltalk

C. C

D. Both(a) and (c)

ANSWER: C

31.Choose the correct remarks.

A. C++ allows any operator to be overloaded.

B. Some of the existing operators cannot be overloaded.

C. Operator precedence cannot be changed.

D. All of the above.

ANSWER: C

32. Which of the following operators cannot be overloaded ?

A. >>

B. ?:

C. .

D. Both (b) and (c)

ANSWER: D

33.C++ encourages structuring .a software as a collection of components that are

A. highly cohesive and loosely coupled

B. not highly cohesive but loosely coupled

C. highly cohesive and tightly coupled

D. not highly cohesive but tightly coupled


ANSWER: A

34.cout stands for

A. class output

B. character output

C. common output

D. call output

ANSWER: C

35.What is the only function all C++ programs must contain?

A. start()

B. system()

C. main()

D. program()

ANSWER: C

36.What punctuation is used to signal the beginning and end of code blocks?

A. { }

B. -> and <-

C. BEGIN and END

D. ( and )

ANSWER: A

37.What punctuation ends most lines of C++ code?

A. . (dot)

B. ; (semi-colon)

C. : (colon)

D. ' (single quote)


ANSWER: B

38.Which of the following is a correct comment?

A. */ Comments */

B. ** Comment **

C. /* Comment */

D. { Comment }

ANSWER: C

39.Which of the following is not a correct variable type?

A. float

B. real

C. int

D. double

ANSWER: B

40.Which of the following is the correct operator to compare two variables?

A. :=

B. =

C. equal

D. ==

ANSWER: D

41.Which of the following is true?

A. 1

B. 66

C. .1

D. All of the above


ANSWER: D

42.Which of the following is the boolean operator for logical-and?

A. &

B. &&

C. |

D. |&

ANSWER: B

43.The void specifier is used if a function does not have return type.

A. True

B. False

C. --

D. --

ANSWER: A

44.The directives for the preprocessors begin with

A. Ampersand symbol (&)

B. Two Slashes (//)

C. Number Sign (#)

D. Less than symbol (<)

ANSWER: C

45.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. Both of these

D. None of these
ANSWER: A

46.There is a unique function in C++ program by where all C++ programs start their execution

A. Start()

B. Begin()

C. Main()

D. Output()

ANSWER: C

47.very function in C++ are followed by

A. Parameters

B. Parenthesis

C. Curly braces

D. None of these

ANSWER: B

48.Which of the following is false?

A. Cout represents the standard output stream in c++.

B. Cout is declared in the iostream standard file

C. Cout is declared within the std namespace

D. None of above

ANSWER: D

49.Every statement in C++ program should end with

A. A full stop (.)

B. A Comma (,)

C. A Semicolon (;)

D. A colon (:)
ANSWER: C

50.Which of the following statement is true about preprocessor directives?

A. These are lines read and processed by the preprocessor

B. They do not produce any code by themselves

C. These must be written on their own line

D. They end with a semicolon

ANSWER: D

51.A block comment can be written by

A. Starting every line with double slashes (//)

B. Starting with /* and ending with */

C. Starting with //* and ending with *//

D. Starting with <!- and ending with -!>

ANSWER: B

52.When writing comments you can

A. Use code and /* comment on the same line

B. Use code and // comments on the same line

C. Use code and //* comments on the same line

D. Use code and <!- comments on the same line

ANSWER: B

53.What is encapsulation?

A. It is collection of similar data items

B. It is combination of similar data items and the function

C. It is the combination of data items and function

D. It is the division of program into independent module


ANSWER: B

54.A variable is/are

A. String that varies during program execution

B. A portion of memory to store a determined value

C. Those numbers that are frequently required in programs

D. None of these

ANSWER: B

55.Which of the following can not be used as identifiers?

A. Letters

B. Digits

C. Underscores

D. Spaces

ANSWER: D

56.Which of the following identifiers is invalid?

A. papername

B. writername

C. typename

D. printname

ANSWER: C

57.Which of the following identifiers is invalid?

A. papername

B. writername

C. typename

D. printname
ANSWER: A

58.To increase the value of c by one which of the following statement is wrong?

A. c++;

B. c = c + 1;

C. c + 1 => c;

D. c += 1

ANSWER: C

59.The result of a Relational operation is always

A. either True or False

B. is less than or is more than

C. is equal or less or more

D. All of these

ANSWER: A

60.What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?

A. 10

B. 9

C. 0

D. 1

ANSWER: A

2 Marks marked rest quetions are of 1 marks

Q1. What is the size of wchar_t in C++?


a) 2
b) 4
c) 2 or 4
d) based on the number of bits in the system

Answer:d
Q2.which datatype is used to represent the absence of paramaters?
a) int
b) short
c) void
d) float

Answer:c

Q3.What does a escape code represent?


a) alert
b) backslash
c) tab
d) form feed

Answer:a

Q4.When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible

Answer:b

Q5.In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned

Answer:b

Q6.To which of these enumerators can be assigned?


a) integer
b) negative
c) enumerator
d) all of the mentioned

Answer:d

Q7. What will happen when defining the enumerated type?


a) it will not allocate memory
b) it will allocate memory
c) it will not allocate memory to its variables
d) none of the mentioned

Answer:a

Q8. Which variable does equals in size with enum variable?


a) int variable
b) float variable
c) string variable
d) none of the mentioned

Answer:a
Q9.Which allows you to create a derived class that inherits properties from more than one base class?
a. Multilevel inheritance
b. Multiple inheritance
c. Hybrid Inheritance
d. Hierarchical Inheritance

Answer:b

Q10. Which feature in OOP allows reusing code?


a. Polymorphism
b. Inheritance
c. Encapsulation
d. Data hiding

Answer:b

Q11. A function that changes the state of the cout object is called a(n) _____
a. member
b. adjuster
c. manipulator
d. operator
Answer:c

Q12. What does C++ append to the end of a string literal constant?
a. a space
b. a number sign (#)
c. an asterisk (*)
d. a null character

Answer:d

Q13. An array element is accessed using


a. a first-in-first-out approach
b. the dot operator
c. a member name
d. an index number

Answer:d

Q14. To hide a data member from the program, you must declare the data member in the _____ section of the class
a. concealed
b. confidential
c. restricted
d. private

Answer:d

Q15.The arguments that determine the state of the cout object are called
a. classes
b. manipulators
c. format flags or state flags
d. state controllers

Answer:c

Q16.Which of the following statements declares a variable that can contain a decimal number?
a. dec payRate;
b. dec hourlyPay
c. float payRate
d. float hourlyPay;

Answer:d

Q17. The statement int num[2][3]={ {1,2}, {3,4}, {5, 6} };


a. assigns a value 2 to num[1][2]
b. assigns a value 4 to num[1][2]
c. gives an error message
d. assigns a value 3 to num[1][2]

Answer:c

Q18.The standard input stream, which refers to the keyboard, is called


a. cin
b. cout
c. stin
d. stout

Answer:a

Q19. Elements in an array are identified by a unique _____


a. data type
b. order
c. subscript
d. symbol

Answer:c

Q20. The statement fwrite ( (char*)&objl, sizeof(objl) );


a. writes the member functions of objl to fl
b. writes the data in objl to fl
c. writes the member functions and me data of obj 1 to fl
d. writes the address of objl to fl

Answer:b

Q21. The body of a C++ function is surrounded by _____


a. parentheses
b. angle brackets
c. curly brackets
d. square brackets

Answer:c

Q22. Which of the following type casts will convert an Integer variable named amount to a Double type?
a. (double) amount
b. (int to double) amount
c. int to double(amount)
d. int (amount) to double

Answer:a

Q23.Which of the following, if any, are valid names for variables?


a. class
b friend
c. void
d. None of the above is valid names for variables

Answer:d

Q24. You have assigned the address of Value to the pointer P, Which statement will display the value stored in
Value?

a. cout<<P;
b. cout<<*Value;
c. cout<<&P;
d. cout<<*<P;

Answer:d

Q25. Type specifier is optional when declaring a function


a. True
b. False

Answer:b

Q26. A pointer to a block of memory is effectively same as an array


a. True
b. False

Answer:a

Q27. Does this mentioning array name gives the base address in all the contexts?
a. Yes
b. No

Answer:b

Q28. Is there any difference int the following declarations?


int fun(int arr[]);
int fun(int arr[2]);
a. Yes
b. No

Answer:b

Q29. Are the expressions arr and &arr same for an array of 10 integers?
a. Yes
b. No

Answer:b

Q30.The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a
pointer to a pointer to a integer is
a) int **fun(float**, char**)
b) int *fun(float*, char*)
c) int ***fun(float*, char**)
d) int ***fun(*float, **char)
Answer:c

Q31.What does your class can hold?


a) data
b) functions
c) both a & b
d) none of the mentioned

Answer:c

Q32.How many specifiers are present in access specifiers in class?


a) 1
b) 2
c) 3
d) 4

Answer:c

Q33. Which is used to define the member of a class externally?


a) :
b) ::
c) #
d) none of the mentioned

Answer:b

Q34. Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b

Answer:d

Q35. Which of the following is a valid class declaration?


a) class A { int x; };
b) class B { }
c) public class A { }
d) object A { int x; };

Answer:a

Q36. The fields in the class in c++ program are by default


a) protected
b) private
c) public
d) none of the mentioned

Answer:b

Q37. Constructors are used to


a) initalize the objects
b) construct the data members
c) both a & b
d) none of the mentioned

Answer:a

Q38. When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned

Answer:a

Q39. Where does the object is created?


a) class
b) constructor
c) destructor
d) attributes

Answer:a

Q40. How to access the object in the class?


a) scope resolution operator
b) ternary operator
c) direct member access operator
d) none of the mentioned

Answer:c

Q41. Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b

Answer:d

Q42. Pick out the other definition of objects.


a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class

Answer:d

Q43. How many objects can present in a single class?


a) 1
b) 2
c) 3
d) as many as possible

Answer:d
Q44. Which special character is used to mark the end of class?
a) ;
b) :
c) #
d) $

Answer: a

Q45.The friend functions are used in situations where:

A. We want to have access to unrelated classes


B. Dynamic binding is required
C. Exchange of data between classes to take place
D. None of the above

Answer: D

Q46. The keyword friend does not appear in

A. The class allowing access to another class


B. The class desiring access to another class
C. The private section of a class
D. The public section of a class

Answer: C

Q47.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 mentioned

Answer:a

Q48. Which keyword is used to declare the friend function?


a) firend
b) friend
c) classfriend
d) myfriend

Answer:b

Q49. What is the syntax of friend function?


a) friend class1 Class2;
b) friend class;
c) friend class
d) None of the mentioned

Answer:a

Q50. 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

Q51. Where does keyword ‘friend’ should be placed?


a) function declaration
b) function definition
c) main function
d) None of the mentioned

Answer:a

Q52. the originator of the C++ language


a)Bjarne Stroustrop
b)Dennis Ritchie
c)Mike Sheridan
d)James Gosling

Answer:a

Q53.Where is the derived class is derived from?


a) derived
b) base
c) both a & b
d) None of the mentioned

Answer:b

Q54. Pick out the correct statement.


a) A derived class’s constructor cannot explicitly invokes its base class’s
constructor.
b) A derived class’s destructor cannot invoke its base class’s destructor.
c) A derived class’s destructor can invoke its base class’s destructor.
d) None of the mentioned

Answer:b

Q55. Which of the following can derived class inherit?


a) members
b) functions
c) both a & b
d) None of the mentioned

Answer:c

Q56. Which operator is used to declare the destructor?


a) #
b) ~
c) @
d) $

Answer:b

Q57.An object is composed of:


a.) properties & methods.
b.) events.
c.) properties & events
d.) All of the above.

Answer:d

Q58.Which statement about objects is true?


a.) One object is used to create one class.
b.) One class is used to create one object.
c.) One object can create many classes.
d.) One class can create many objects.
e.) There is no relationship between objects and classes.

Answer: d

Q59.Which feature is needed to make a programming language object oriented?


a.) Encapsulation
b.) Inheritance
c.) Polymorphism
d.) Both a and b.
e.) All of the above.

Answer: e

Q60.We should think of the practice of object-oriented programming as:


a.) a simple answer to the complex problem of creating software.
b.) an incremental improvement to the problem of creating software.
c.) the way to get rid of a werewolf.
d.) Both a and b.
e.) All of the above.

Answer: b

Q61.Encapsulation makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.
e.) All of the above.

Answer: c

Q62.Inheritance makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.
e.) All of the above.

Answer: a

Q63.Polymorphism makes it easier to:


a.) reuse and modify existing modules of code.
b.) write and read code by sharing method names.
c.) hide and protect data from external code.
d.) Both a and b.

Answer: b

Q64.Which element treats as a critical element in the program development in OOP?


a. Data b. function
c. Object d. classes

Answer:a

Q65.OOP uses which approach


a. Top-down
b. bottom-up

Answer: b

Q66.OOP allows us to decompose a problem into a number of entities called


a. Object
b. classes
c. Data
d. Function

Answer:a

Q67. Objects may communicate with each other through


a. Data
b. Methods
c. Object
d. Classes

Answer: b

Q68. New methods & data cab be easily added


a. True
b. false

Answer:a

Q69. Set of objects is called as


a. Class
b. Object
c. Methods
d. Data

Answer:a

Q70. The entire set of data & code of an object can be made which data type using the concept of class
a. User-defined
b. static
c. global
d. derived

Answer:a

Q71. Wrapping up of data & methods into a single unit is called as


a. Inheritance
b. polymorphism
c. Encapsulation
d. Abstraction

Answer:c

Q72. What provide the interface between the object’s data & the program
a. Data
b. class
c. methods
d.Encapsulation

Answer:c

Q73. The insulation of data from direct access by the program is called as
a. Encapsulation
b. Data hiding
c. Private
d. Data Abstraction

Answer:b

Q74. What is the process by which object of one class acquires the properties of object of another class.
a. Encapsulation
b. Data hiding
c. Inheritance
d.Polymorphism

Answer:c

Q75. The concept of inheritance provides the idea of


a. Taking more than one form
b. reusability
c. data hiding
d.modularity

Answer:b

Q76. The derived class is known as


a. Superclass
b. subclass
c. parentclass
d. mainclass

Answer:b

Q77. The class from which the subclass derives the properties is called as
a. mainclass
b. subclass
c. baseclass
d. Superclass

Answer:d

Q78. The property or the ability to take more than one form is called as
a. Encapsulation
b. Polymorphism
c. Inheritance
d. Manyforms

Answer:b

Q79. For what implemention Polymorphism is extensively used?


a. Encapsulation
b. Data hiding
c. Inheritance
d. Methods

Answer:c

Q80. The process of linking of a procedure call with the code to be executed is called as
a. Binding
b. Loading
c. Assembling
d. Debuging

Answer:a

Q81. What is the process in which the code to be linked with the procedure call is not know till execution time
?
a. Binding
b. early binding
c. static binding
d. dynamic binding

Answer:d

Q82. When the code to be linked with the call is known at compile time that situation is called as
a. Binding
b. late binding
c. static binding
d. dynamic binding

Answer:c

Q83. The signature of function is


a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above

Answer: a

Q84. Overloading of constructor function


a) is similar to function overloading
b) different from an overloaded function as it can’t return a value
c) not permitted in C++
d) none of the above

Answer: b
Q85. The binding of a function call at runtime is
a) Static binding
b) Early binding
c) Late binding
d) Runtime binding

Answer: c

Q86. A destruction function


a) Takes no argument and has no return type not even void
b) Has name similar to that of class, preceded by tilde(~) symbol
c) Is used to destruct an object, constructed through constructor function
d) All of the above

Answer: d

Q87. Which of the following statements regarding destructor function is false?


a) Destructors do not accept any arguments, nor do they return any values
b) Destructors can be inherited
c) Member functions may be called from within a destructor
d) Destructor functions are called automatically when an object is destroyed

Answer: b

Q88. Which constructor will initialize the base class data member?
a) derived class
b) base class
c) class
d) None of the mentioned

Answer:b

Q89. A remote control that is used to turn on or off some machine is also called a(n) _____.
a) class
b) interface
c) message
d) instance

Answer:b

Q90. In a student grading system, Student Last Name, Student Address, and Final Course Grade would all be
classified as what?
a)Inheritance
b)Information
c)Encapsulation
d)Polymorphism

Answer:b

Q91. What part of object-oriented technology defines superclass and subclass relationships?
a) Inheritance
b) Scalability
c) Encapsulation
d) Polymorphism

Answer:a

Q92. In a student grading system, objects from different classes communicate with each other. These
communications are known as _____.
a) inheritance
b) polymorphism
c) messages
d) concealment

Answer:c

Q93. When an object has many forms, it has _____.


a) Inheritance
b) Scalability
c) Encapsulation
d) Polymorphism

Answer:d

Q94. What term is used to describe the internal representation of an object that is hidden from view outside the
object's definition?
a) Encapsulation
b) Expandable
c) Polymorphism
d) Inheritance

Answer:a

Q95. What programming language model is organized around "objects" rather than "actions"?
a) Java
b) OOB
c) Perl
d) C+

Answer:b

Q96. What are the instructions called that tell a system what, how, and when to do something?
a) Object-oriented technology approach
b) Object-oriented database
c) Program
d) Database management

Answer:c

Q97. What common technique attempts to save time and energy by reducing redundant work in object-oriented
programming?
a) Reduce lines of programming
b) Reuse of code
c) Reduce size of systems being developed
d) Merging different systems together

Answer:b

Q98. What kind of programming language is Java?


a) Object-oriented programming language
b) Relational programming language
c) Sixth-generation programming language
d) Database management programming language

Answer:a

Q99. Which language is not a true object-oriented programming language?


a.) VB.NET
b.) VB 6
c.) C++
d.) C#

Answer:b

Q100.What are cin and cout?


(A) pointers
(B) functions
(C) operator
(D) stream objects

Answer: D

Q101. What is used to convert the value of one type to another


a. Data type
b. variable
c. typecasting

Answer:a

Q102. How many numbers of java constants are present?


a. 6
b. 4
c. 5
d. 3

Answer:b

Q103. Whaere did Instance and class variables are declare?


a. Inside
b. outside
c. in the main

Answer:a

Q104. Class variables are...... to the class


a. Local
b. static
c. global
d. derived

Answer:c

Q105. Instance variables take .... values for each object


a. Different b. same c. non-zero
Answer:a

Q106. If a class C is derived from class B, which is derived from class A, all through public
inheritance, then a class C member function can access
a) protected and public data only in C and B.
b) protected and public data only in C.
c) private data in A and B.
d) protected data in A and B.

Answer:d

Q107. Usually a pure virtual function


a) has complete function body.
b) will never be called.
c) will be called only to delete an object.
d) is defined only in derived class.

Answer:d

Q108. RunTime Polymorphism is achieved by ______


a) friend function
b) virtual function
c) operator overloading
d) function overloading

Answer:b

Q109. In C++, dynamic memory allocation is accomplished with the operator ____
a) new
b) this
c) malloc( )
d) delete

Answer:a

Q110. What type of comments does c++ support?


a) single line
b) multi line
c) single line and multi line
d) none of the mentioned

Answer: c

Q111. A struct is the same as a class except that


a) there are no member functions.
b) all members are public.
c) cannot be used in inheritance hierarchy.
d) it does have a this pointer.

Answer:c

Q112. Pure virtual functions


a) have to be redefined in the inherited class.
b) cannot have public access specification.
c) are mandatory for a virtual class.
d) None of the above.

Answer:a

Q113.Use of virtual functions implies


a) overloading
b) overriding
c) static binding
d) dynamic binding

Answer:d

Q114.Which of the following is false for cin?


a) It represents standard input.
b) It is an object of istream class.
c) It is a class of which stream is an object.
d) Using cin the data can be read from user’s terminal.

Answer:c

Q115.It is possible to declare as a friend


a) a member function
b) a global function
c) a class
d) all of the above

Answer:d

Q116.In multiple inheritance


a) the base classes must have only default constructors
b) cannot have virtual functions
c) can include virtual classes
d) None of the above.

Answer:c

Q117.Identify the operator that is NOT used with pointers


a) ->
b) &
c) *
d) >>

Answer:d

Q118.The members of a class, by default, are


a) public
b) protected
c) private
d) mandatory to specify

Answer:c

Q119.Given a class named Book, which of the following is not a valid constructor?
a) Book ( ) { }
b) Book ( Book b) { }
c) Book ( Book &b) { }
d) Book (char* author, char* title) { }

Answer:b

Q120.Which of the statements is true in a protected derivation of a derived class from a base class?
a) Private members of the base class become protected members of the derived class
b) Protected members of the base class become public members of the derived class
c) Public members of the base class become protected members of the derived class
d) Protected derivation does not affect private and protected members of the derived
class.

Answer:c

Q121.How many constructors can a class have?


a) 0
b) 1
c) 2
d) any number

Answer:d

Q122.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

Q123.RunTime polymorphism is achieved by ___________


a) friend function
b) virtual function
c) operator overloading
d) function overloading

Answer:b

Q124.If there is a pointer p to object of a base class and it contains the address of an object of a
derived class and both classes contain a virtual member function abc(), then the statement
p->abc(); will cause the version of abc() in the __________class to be executed.
a) Base Class
b) Derived class
c) Produces compile time error
d) produces runtime error

Answer:b

Q125.We can output text to an object of class ostream using 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

Q126.Which of the following is not the characteristic of constructor.


a) They should be declared in the public section.
b) They do not have return type.
c) They can not be inherited.
d) They can be virtual.

Answer:d

Q127.Name the header file to be included for the use of built in function isalnum()
a) string.h
b) process.h
c) ctype.h
d) dos.h

Answer:c

Q128.A class defined within another class is:


a) Nested class
b) Inheritance
c) Containership
d) Encapsulation

Answer:a

Q129.The major goal of inheritance in c++ is:


a) To facilitate the conversion of data types.
b) To help modular programming.
c) To extend the capabilities of a class.
d) To hide the details of base class.

Answer:c

Q130.The following can be declared as friend in a class


a) an object
b) a class
c) a public data member
d) a private data member

Answer:b

Q131.A copy constructor takes


a) no argument
b) one argument
c) two arguments
d) arbitrary no. of arguments

Answer:b

Q132.Overloading a postfix increment operator by means of a member function takes


a) no argument
b) one argument
c) two arguments
d) three arguments

Answer:a

Q133.Which of the following ways are legal to access a class data member using this pointer?
a) this.x
b) *this.x
c) *(this.x)
d) (*this).x

Answer:d

Q134.Which of the following declarations are illegal?


a) void *ptr;
b) char *str = “hello”;
c) char str = “hello”;
d) const *int p1;

Answer:c

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


a) ->
b) =
c) ( )
d) *

Answer:d

Q136.If a base class destructor is not virtual, then


a) It can not have a function body.
b) It can not be called.
c) It can not be called when accessed from pointer.
d) Destructor in derived class can not be called when accessed through a pointer to the base
class.

Answer:d

Q137.Which of the following statement is valid?


(A) We can create new C++ operators.
(B) We can change the precedence of the C++ operators.
(C) We can change the associativity of the C++ operators.
(D) We can not change operator templates.

Answer:d

Q138.Which can be passed as an argument to a function?


a) constant
b) expression
c) another function
d) all of the above.

Answer:a

Q139.The operator << when overloaded in a class


a) must be a member function
b) must be a non member function
c) can be both (A) & (B) above
d) cannot be overloaded

Answer:c
Q140.Data members which are static
a) cannot be assigned a value
b) can only be used in static functions
c) cannot be defined in a Union
d) can be accessed outside the class

Answer:b

Q141.this pointer
a) implicitly points to an object.
b) can be explicitly used in a class.
c) can be used to return an object.
d) All of the above.

Answer:d

Q142.The operator that cannot be overloaded is


a) ++
b) ::
c) ( )
d) ~

Answer:b

Q143.A struct is the same as a class except that


a) there are no member functions.
b) all members are public.
c) cannot be used in inheritance hierarchy.
d) it does have a this pointer.

Answer:c

Q.144 What is the use of the indentation in c++?


a) distinguishes between comments and code
b) r distinguishes between comments and outer data
c) both a and b
d) none of the mentioned

Answer: a

Q144.What is a comment in c++?


a) comments are parts of the source code disregarded by the compiler
b) comments are executed by compiler to find the meaning of the comment
c) comments are executable
d) none of the mentioned

Answer: a

Q145. Which of the following is not the member of class?


A. Static function
B. Friend function
C. Const function
D. Virtual function

Answer: B
Q.146. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function

Answer: B

Q.147 How many instances of an abstract class can be created?


A. 1
B. 5
C. 13
D. 0

Answer: D

Q.148 Which of the following cannot be friend?


A. Function
B. Class
C. Object
D. Operator function

Answer: C

Q.149 In structured programming, the problem is divided into various ______.


A. modules
B. functions
C. structures
D. objects

Answer: B

Q.150 Which header file must be included for cin and cout?
(A) stdio.h
(B) conio.h
(C) iostream.h
(D) Both iostream.h and conio.h

Answer: C

Q.151 Which one of the following is correct about the statements given below?

I All function calls are resolved at compile-time in Procedure Oriented Programming.


II All function calls are resolved at compile-time in OOPS.

A. Only II is correct.
B. Both I and II are correct.
C. Only I is correct.
D. Both I and II are incorrect.

Answer: C

Q.152. Use of __________ protects data from inadvertent modifications

A. protect() member function


B. private access specifier
C. class protection operator, @
D. none of these

Answer: B

Q.153 A suitable place to store Class declarations is _______.

A. none of these
B. their own header files
C. Auxiliary .cpp file
D. main .cpp files, along with function definitions

Answer: B

Q.154 Inline Functions are invoked at


A. Run time
B. Compile time
C. Depends on how it is invoked
D. Both b and c above

Answer: B

Q.155 Which of the following is false for cin?


(A)It represents standard input.
(B)It is an object of istream class.
(C)It is a class of which stream is an object.
(D)Using cin the data can be read from user’s terminal

Answer: C

Q156.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

Q157.The smallest individual unit in a program is ………


a) Keyword
b) Identifier
c) Token
d) None of the above

Answer: C

Q.158 What is the associativity of add(+);


a) right to left
b) left to right
c) both of these
d) None of the mentioned

Answer:b

Q.159 Which operator is having the highest precedence in c++?


a) array subscript
b) Scope resolution operator
c) static_cast
d) dynamic_cast

Answer:b

Q160.In C++, the statements are enclosed within


a) parenthesis
b) square brackets
c) curly brackets
d) None of the above

Answer: C

Q161.“H” is an example of
a) character literal
b) string literal
c) variable
d) None of the above

Answer: B

Q.162 y=x=2; in C++ will result in


a) compilation error
b) runtime error
c) assignment of value to x then to y
d) None of the above

Answer: C

Q.163 Modules operator (%) has higher precedence than


a) Divide (/) operator
b) Multiply (*) operator
c) Negation (unary minus)
d) Bitwise left shift operator

Answer: C

Q.164 The result of the following statement is


int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;
a) ans=7, y=7
b) ans=8,y=7
c) ans=8,y=8;
d) none of the above

Answer: C

Q165 Consider the following if construct


If(x=0)
cout<<”Inside loop!”;
cout<<”Outside loop”;
The result of the above code segment is.

a) inside loop
b) outside loop
c) both (a) & (b)
d) none of the above

Answer: B

166. The result of 2 & 3 is


a) 2
b) 3
c) 5
d) none of the above

Answer: A

Q167 The following is a valid statement in C++


a) int x=(int)2.50;
b) int x=int(2.50);
c) Both (a) & (b)
d) None of the above

Answer: C

Q.168 Which of the following operator can be overloaded


a) Member access operator ( . & .*)
b) Conditional operator (?:)
c) Scope resolution operator (::)
d) None of the above

Answer: D

Q.169 When a member function of a class call another member function, it is


a) Nesting of classes
b) Nesting of functions
c) Nesting of objects
d) None of the above

Answer: B

Q.170 Functions can returns


a) arrays
b) reference
c) object
d) all of the above

Answer: D

Q.171 Pick the odd one out


a) array type
b) character type
c) boolean type
d) integer type
Answer:a

Q.172 Which type is best suited to represent the logical values?


a) integer
b) boolean
c) character
d) all of the mentioned

Answer:b

Q.173 Identify the user-defined types from the following?


a) enumeration
b) classes
c) both a and b
d) int

Answer:c

Q174.Which of the following statements are true?


int f(float)
a) f is a function taking an argument of type int and retruning a floating point number
b) f is a function taking an argument of type float and returning a integer.
c) f is a function of type float
d) none of the mentioned

Answer:b

Q.175 Pick the odd one out.


a) integer, character, boolean, floating
b) enumeration, classes
c) integer, enum, void
d) arrays, pointer, classes

Answer:c

Q.176. When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible

Answer:b

Q.177. Is bool a fundamental datatype in C++?


a) Yes
b) No, it is a typedef of unsigned char
c) No, it is an enum of {false,true}
d) No, it is expanded from macros
Answer:a

Q.178 Find the odd one out:


a) std::vector<int>
b) std::vector<short>
c) std::vector<long>
d) std::vector<bool>

Answer:d

Q.179 What is the value of the bool?


bool is_int(789.54)
a) True
b) False
c) 1
d) none of the mentioned

Q.180 What happens when a null pointer is converted into bool?


a) An error is flagged
b) bool value evaluates to true
c) bool value evaluates to false
d) the statement is ignored

Answer:c

Q.181 Which of the following statements are false?


a) bool can have two values and can be used to express logical expressions.
b) bool cannot be used as the type of the result of the function.
c) bool can be converted into integers implicitly
d) a bool value can be used in arithemetic expressions.

Answer:b

Q.182 For what values of the expression is an if-statement block not executed?
a) 0 and all negative values
b) 0 and -1
c) 0
d) 0, all negative values, all positive values except 1

Answer:c

Q.183 Which of the two operators ++ and — work for the bool datatype in C++?
a) None
b) ++
c) –
d) Both

Answer:b

Q.184 What is the output of the following program? 2Marks

#include <iostream>
using namespace std;
int f(int p, int q)
{
if (p > q)
return p;
else
return q;
}
main()
{
int a = 5, b = 10;
int k;
bool x = true;
bool y = f(a, b);
k =((a * b) + (x + y));
cout << k;
}

a) 55
b) 62
c) 52
d) none of the mentioned

Answer:c

Q.185 What is the value of p? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int p;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p = ((x + y) + (a + b));
cout << p;
return 0;
}

a) 0
b) 16
c) 12
d) 2

Answer:b

Q.186 Evaluate the following


(false && true) || false || true
a) 0
b) 1
c) false
d) none of the mentioned
Answer:b

Q.187 How many characters are specified in the ASCII scheme?


a) 64
b) 128
c) 256
d) none of the mentioned

Answer:b

Q.188 Select the right option.


Given the variables p, q are of char type and r, s, t are of int type 2 Marks
1. t = (r * s) / (r + s);
2. t = (p * q) / (r + s);
a) 1 is true but 2 is false
b) 1 is false and 2 is true
c) both 1 and 2 are true
d) both 1 and 2 are false

Answer:c

Q.189 How do we represent a wide character of the form wchar_t?


a) L’a’
b) l’a’
c) L[a]
d) la

Answer:a

Q.190 What is the output of this program? 2 Marks

#include <stdio.h>
int main()
{
char a = '\012';

printf("%d", a);
return 0;
}
a) Compiler error
b) 12
c) 10
d) Empty

Answer:c
Q.191 In C++, what is the sign of character data type by default?
a) Signed
b) Unsigned
c) Implementation dependent
d) None of these
Answer:c

Q.192 8. Is the size of character literals different in C and C++?


a) Implementation defined
b) Can’t say
c) Yes, they are different
d) No, they are not different

Answer:c

Q.193 The size_t integer type in C++ is?


a) Unsigned integer of at least 64 bits
b) Signed integer of at least 16 bits
c) Unsigned integer of at least 16 bits
d) Signed integer of at least 64 bits

Answer:c

Q.194 What is the output of the following program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int x = -1;
unsigned int y = 2;

if(x > y) {
cout << "x is greater";
} else {
cout << "y is greater";
}
}
a) x is greater
b) y is greater
c) Implementation defined
d) Arbitrary

Answer:a

Q.195 Which of these expressions will return true if the input integer v is a power of two?
a) (v | (v + 1)) == 0;
b) (v & (v – 1)) == 0;
c) (v | (v + 1)) == 0;
d) (v & (v – 1)) == 0;

Answer:d

Q.196 What is the value of the following 8-bit integer after all statements are executed?
int x = 1; 2 Marks
x = x << 7;
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined
View Answer

Answer:d

Q.197 What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7; 2 Marks
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined

Answer:d

Q.198 Which of these expressions will make the rightmost set bit zero in an input integer x?
a) x = x | (x-1)
b) x = x & (x-1)
c) x = x | (x+1)
d) x = x & (x+1)

Answer:b

Q.199 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)

Answer:c

Q.200 Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)

Answer:c

Q.201 What will be the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int a = 8;
cout << "ANDing integer 'a' with 'true' :" << a && true;
return 0;
}
a) ANDing integer ‘a’ with ‘true’ :8
b) ANDing integer ‘a’ with ‘true’ :0
c) ANDing integer ‘a’ with ‘true’ :1
d) None of the mentioned

Answer:a

Q.202 What will be output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
cout << l << k;
return 0;
}
a) compile time error
b) -1 1
c) 1 -1
d) implementation defined

Answer:b

Q.203 What will be output of this function? 2 Marks

int main()
{
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}
a) 0
b) 1
c) Compiler error may be possible
d) Runtime error may be possible

Answer:c

Q.204 Identify the correct option.


a) enumerators are contants
b) enumerators are user defined types
c) enumerators are unchangables.
d) character

Answer:b

Q.205 In which type does the enumerators are stored by the compiler?
a) string
b) integer
c) float
d) none of the mentioned

Answer:b

Q.206 To which of these enumerators can be assigned?


a) integer
b) negative
c) enumerator
d) all of the mentioned

Answer:d

Q.207 What will happen when defining the enumerated type?


a) it will not allocate memory
b) it will allocate memory
c) it will not allocate memory to its variables
d) none of the mentioned

Answer:a

Q.208 Which variable does equals in size with enum variable?


a) int variable
b) float variable
c) string variable
d) none of the mentioned

Answer:a

Q.209 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
enum cat {
temp = 7
};
int main()
{
int age = 14;
age /= temp;
cout << "If you were cat, you would be " << age << endl;
return 0;
}
a) If you were cat, you would be 5
b) If you were cat, you would be 2
c) If you were cat, you would be 7
d) none of the mentioned

Answer:b

Q.210 What is the output of this program? 2 Marks


#include <iostream>
using namespace std;
enum test {
A = 32, B, C
};
int main()
{
cout << A << B<< C;
return 0;
}
a) 323334
b) 323232
c) 323130
d) none of the mentioned

Answer:a

Q.211 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
enum colour {
green, red, blue, white, yellow, pink
};
int main()
{
cout << green<< red<< blue<< white<< yellow<< pink;
return 0;
}
a) 0123456
b) 1111111
c) compile time error
d) runtime error

Answer:a

Q.212 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i <= zee; i++) {
printf("%d ", i);
}
return 0;
}
a) 012
b) 123
c) compile time error
d) runtime error
Answer:c

Q.213 What is output of the this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int i;
enum month {
JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
};
for (i = MAR; i <= NOV; i++)
cout << i;
return 0;
}
a) 01234567891011
b) 123456789101112
c) 34567891011
d) 123456789

Answer:c

Q.214 What does your class can hold?


a) data
b) functions
c) both a & b
d) none of the mentioned

Answer:C

Q.215 How many specifiers are present in access specifiers in class?


a) 1
b) 2
c) 3
d) 4

Answer:c

Q.216 Which is used to define the member of a class externally?


a) :
b) ::
c) #
d) none of the mentioned

Answer:b

Q.217 Which other keywords are also used to declare the class other than class?
a) struct
b) union
c) object
d) both a & b

Answer:d

Q.218. What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class rect
{
int x, y;
public:
void val (int, int);
int area ()
{
return (x * y);
}
};
void rect::val (int a, int b)
{
x = a;
y = b;
}
int main ()
{
rect rect;
rect.val (3, 4);
cout << "rect area: " << rect.area();
return 0;
}
a) rect area:12
b) rect area: 12
c) rect area:24
d) none of the mentioned

Answer:b

Q.219 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class CDummy
{
public:
int isitme (CDummy& param);
};
int CDummy::isitme (CDummy& param)
{
if (&param == this)
return true;
else
return false;
}
int main ()
{
CDummy a;
CDummy *b = &a;
if (b->isitme(a)) {
cout << "execute";
}
else
{
cout<<"not execute";
}
return 0;
}
a) execute
b) not execute
c) none of the mentioned
d) both a & b

Answer:a

Q.220 Which of the following is a valid class declaration?


a) class A { int x; };
b) class B { }
c) public class A { }
d) object A { int x; };

Answer:a

Q.221 The fields in the class in c++ program are by default


a) protected
b) private
c) public
d) none of the mentioned

Answer:b

Q.222 Constructors are used to


a) initalize the objects
b) construct the data members
c) both a & b
d) none of the mentioned

Answer:a

Q.223 When struct is used instead of the keyword class means, what will happen in the program?
a) access is public by default
b) access is private by default
c) access is protected by default
d) none of the mentioned

Answer:a

Q.224 Where does the object is created?


a) class
b) constructor
c) destructor
d) attributes

Answer:a

Q.225 How to access the object in the class?


a) scope resolution operator
b) ternary operator
c) direct member access operator
d) none of the mentioned

Answer:c

Q.226 Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) Both a & b

Answer:d

Q.227 What is the output of the following program? 2 Marks

#include <iostream>
using namespace std;
class Box
{
public :
double length;
double breadth;
double height;
};
int main( )
{
Box Box1;
double volume;
Box1.height = 5;
Box1.length = 6;
Box1.breadth = 7.1;
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl;
return 0;
}
a) 210
b) 213
c) 215
d) 217

Answer:b

Q.228 What is the output of the program? 2 Marks


#include <iostream>
using namespace std;
class Rect
{
int x, y;
public:
void set_values (int,int);
int area ()
{
return (x * y);
}
};
void Rect::set_values (int a, int b) {
x = a;
y = b;
}
int main ()
{
Rect recta, rectb;
recta.set_values (5, 6);
rectb.set_values (7, 6);
cout << "recta area: " << recta.area();
cout << "rectb area: " << rectb.area();
return 0;
}
a) recta area: 30 rectb area: 42
b) recta area: 20 rectb area: 34
c) recta area: 30 rectb area: 21
d) none of the mentioned

Answer:a

Q.229 Pick out the other definition of objects.


a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class

Answer:d

Q.230 How many objects can present in a single class?


a) 1
b) 2
c) 3
d) as many as possible

Answer:d

Q.231 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class sample
{
private:
int var;
public:
void input()
{
cout << var;
}
void output()
{
cout << "Variable entered is ";
cout << var << "\n";
}
};
int main()
{
sample object;
object.input();
object.output();
object.var();
return 0;
}
a) Enter an integer 5
Variable entered is 5
b) runtime error
c) error
d) none of the mentioned

Answer:c

Q.232 Pick out the correct syntax of operator conversion.


a) operator float()const
b) operator float()
c) operator const
d) None of the mentioned

Answer:a

Q.233 Which special character is used to mark the end of class?


a) ;
b) :
c) #
d) $

Answer: a

Q.234 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class number
{
int i;
public:
int geti();
void puti(int j);
};
int number::geti()
{
return i;
}
void number::puti(int j)
{
i = j;
}
int main()
{
number s;
s.puti(10);
cout << s.geti( );
return 0;
}
a) 10
b) 11
c) 20
d) 22

Answer:a

Q.235 Which class is used to design the base class?


a) abstract class
b) derived class
c) base class
d) None of the mentioned

Answer:a

Q.236 Which is used to create a pure virtual function ?


a) $
b) =0
c) &
d) !

Answer:b

Q.237 Which is also called as abstract class?


a) virtual function
b) pure virtual function
c) derived class
d) None of the mentioned

Answer:b
Q.238 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class p
{
protected:
int width, height;
public:
void set_values (int a, int b)
{
width = a; height = b;
}
virtual int area (void) = 0;wa
};
class r: public p
{
public:
int area (void)
{
return (width * height);
}
};
class t: public p
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
r rect;
t trgl;
p * ppoly1 = &rect;
p * ppoly2 = &trgl;
ppoly1->set_values (4, 5);
ppoly2->set_values (4, 5);
cout << ppoly1 -> area() ;
cout << ppoly2 -> area();
return 0;
}
a) 1020
b) 20
c) 10
d) 2010

Answer:d

Q.239 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class MyInterface
{
public:
virtual void Display() = 0;
};
class Class1 : public MyInterface
{
public:
void Display()
{
int a = 5;
cout << a;
}
};
class Class2 : public MyInterface
{
public:
void Display()
{
cout <<" 5" << endl;
}
};
int main()
{
Class1 obj1;
obj1.Display();
Class2 obj2;
obj2.Display();
return 0;
}
a) 5
b) 10
c) 5 5
d) None of the mentioned

Answer:c

Q.240 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class sample
{
public:
virtual void example() = 0;
};
class Ex1:public sample
{
public:
void example()
{
cout << "ubuntu";
}
};
class Ex2:public sample
{
public:
void example()
{
cout << " is awesome";
}
};
int main()
{
sample* arra[2];
Ex1 e1;
Ex2 e2;
arra[0]=&e1;
arra[1]=&e2;
arra[0]->example();
arra[1]->example();
}
a) ubuntu
b) is awesome
c) ubuntu is awesome
d) None of the mentioned

Answer:c

Q.241 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
class Base
{
public:
virtual void print() const = 0;
};
class DerivedOne : virtual public Base
{
public:
void print() const
{
cout << "1";
}
};
class DerivedTwo : virtual public Base
{
public:
void print() const
{
cout << "2";
}
};
class Multiple : public DerivedOne, DerivedTwo
{
public:
void print() const
{
DerivedTwo::print();
}
};
int main()
{
Multiple both;
DerivedOne one;
DerivedTwo two;
Base *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &one;
array[ 2 ] = &two;
for ( int i = 0; i < 3; i++ )
array[ i ] -> print();
return 0;
}
a) 121
b) 212
c) 12
d) None of the mentioned

Answer:b

Q.242 Pick out the correct option.


a) We cannot make an instance of an abstract base class
b) We can make an instance of an abstract base class
c) Both a & b
d) None of the mentioned

Answer:a

Q.243 Where does the abstract class is used?


a) base class only
b) derived class
c) both a & b
d) None of the mentioned

Answer:a

Q.244 What are the essential operators in c++?


a) +
b) |
c) <=
d) All of the mentioned

Answer:d

Q.245 In which direction does the assignment operation will take place?
a) left to right
b) right to left
c) top to bottom
d) None of the mentioned
Answer:b

Q.246 Pick out the compound assignment statement.


a) a = a - 5
b) a = a / b
c) a -= 5
d) None of the mentioned

Answer:c

Q.247 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main ()
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a:";
cout << a;
cout << " b:";
cout << b;
return 0;
}
a) a:4 b:7
b) a:10 b:4
c) a:4 b:10
d) None of the mentioned

Answer:a

Q.248 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main ()
{
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}
a) 2
b) 7
c) 9
d) 14

Answer:b
Q.249 What is the output of this program? 2 Marks

#include <iostream>
using namespace std;
int main()
{
int a = 0;
int b = 10;
if ( a && b )
{
cout << "true"<< endl ;
}
else
{
cout << "false"<< endl ;
}
return 0;
}
a) true
b) false
c) error
d) None of the mentioned

Answer:b

Q.250 Where does the default parameter can be placed by the user?
a) leftmost
b) rightmost
c) both a & b
d) none of the mentioned

Answer:b
Unit 2 : Classes & Objects

Question Bank

AY 2020-21 SEM-II Page 1


MCQ’s on Object & classes
1) Where does the object is created?

A. Class
B. Constructor
C. Destructors
D. Attributes

Ans : A

Explanation: In class, only all the listed items except class will be declared.
2)Constructor is executed when __ _.

A. An object goes out of scope.


B. A class is declared
C. An object is created
D. An object is used
Ans : C

Explanation: Constructor is executed when An object is created.


3)Which of the following is a valid class declaration?

A. Class A { int x; };
B. Class B { }
C. Public class A { }
D. Object A { int x; };
Ans : A

Explanation: Class A { int x; }; is a valid class declaration.


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

A. Default
B. Break
C. Protected
D. Asm
Ans : C

Explanation: Protected keywords is used to control access to a class member


5)Which of the following statements is incorrect?

A. Destructor of base class should always be static


B. Destructor of base class should always be virtual.

AY 2020-21 SEM-II Page 2


C. Destructor of base class should not be virtual.
D. Destructor of base class should always be private.
Ans : B

Explanation: Destructor of base class should always be virtual statements is incorrect


6)Which operator can not be overloaded?

A. +
B. ::
C. -
D. *
Ans : B

Explanation: :: operator can not be overloaded


7)What is the size of empty class?

A. 0
B. 2
C. 4
D. 1
Ans : D

Explanation: When we create object of empty class at that time State of that object is nothing.
Behaviour of that object is also nothing, but compiler assigns a unique address to that object.
Memory in Computer is always organized in the form of bytes and minimum memory available at
object address location is 1 byte. That's why size of object of empty class is 1 byte.
8) How to access the object in the class?

A. Ternary operator
B. Scope resolution operator
C. Direct member access operator
D. None of the above
Ans : C

Explanation: Objects in the method can be accessed using direct member access operator which is
(.).
9) When struct is used instead of the keyword class means, what will happen in the program?

A. Access is public by default


B. Access is private by default
C. Access is protected by default
D. None of the mentioned

AY 2020-21 SEM-II Page 3


Ans : A

Explanation: Access is public by default will happen Whenstruct is used instead of the keyword
class.
10) Which of the following is not a member of class?

A. Static Function.
B. Friend Function
C. Const Function
D. Virtual Function

Ans : B

Explanation: Friend function is not a member of class.


11) Which of the following cannot be passed to a function in C++ ?
(A) Constant
(B) Structure
(C) Array
(D) Header file

Answer: (D)

Explanation: Header file can not be passed to a function in C++. While array, constant and
structure can be passed into a function.
So, option (D) is correct.
12) Which of the following is not a correct statement?
(A) Every class containing abstract method must be declared abstract.
(B) Abstract class can directly be initiated with ‘new’ operator.
(C) Abstract class can be initiated.
(D) Abstract class does not contain any definition of implementation.

Answer: (B)

Explanation:
• Every class containing abstract method must be declared abstract. Correct Declaration is
required.
• Abstract class can directly be initiated with ‘new’ operator. No it can’t be initiated directed by
only ‘new’ operator. So, it is Inorrect
• Abstract class can be initiated.Correct
• Abstract class does not contain any definition of implementation.Correct
So, option (B) is correct.

AY 2020-21 SEM-II Page 4


13) Which of the following is true?
(A) All objects of a class share all data members of class
(B) Objects of a class do not share non-static members. Every object has its own copy.
(C) Objects of a class do not share codes of non-static methods, they have their own copy
(D) None of the above

Answer: (B)

Explanation: Every object maintains a copy of non-static data members. For example, let
Student be a class with data members as name, year, batch. Every object of student will have its
own name, year and batch. On a side note, static data members are shared among objects.
All objects share codes of all methods. For example, every student object uses same logic to find
out grades or any other method.
14) A member function can always access the data in _______ _ , (in C++).
(A) the class of which it is member
(B) the object of which it is a member
(C) the public part of its class
(D) the private part of its class

Answer: (A)

Explanation: A member function can access it’s class member variables, irrespective of the
access specifier in which the member variable is declared.So, a member function can always
access the data in the class of which it is a member.
So, option (A) is correct.
15) Data members and member functions of a class in C++ program are by default

A. protected
B. public
C. private
D. None
View Answer
Answer: C
16) Which operator is used to allocate an object dynamically of a class in C++?

A. Scope resolution operator


B. Conditional operator
C. New operator
D. Membership access
Answer: C
17) Which is used to define the member function of a class externally?

A. :

AY 2020-21 SEM-II Page 5


B. ::
C. #
D. None
Answer: B
18) By default functions available in C++ language are

A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
E. All
Answer: E
19) When you create an object of a class A like A obj ; then which one will be called
automatically

A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
Answer: A
20) The class in C++ which act only as a base class and object of it cannot be created is

A. parent class
B. super class
C. abstract class
D. none of the above
Answer: C

Q.001 Instance of which type of class can’t be created?


A Anonymous class
B Nested class
C Parent class
D Abstract class
Correct D

Q.002 What is the scope of a class nested inside another class?


A Protected scope
B Private scope
C Global scope
D Depends on access specifier and inheritance used
Correct D

AY 2020-21 SEM-II Page 6


Q.003 The object can’t be _ _
A Passed by reference
B Passed by value
C Passed by copy
D Passed as function
Correct D

Q.004 If class A has add() function with protected access, and few other members in public.
Then class B inherits class A privately. Will the user will not be able to call __
from the object of class B.
A Any function of class A
B The add() function of class A
C Any member of class A
D Private, protected and public members of class A
Correct D
Q.005 If an abstract class has all the private members, then _
A No class will be able to implement members of abstract class
B Only single inheritance class can implement its members
C Only other enclosing classes will be able to implement those members
D No class will be able to access those members but can implement.
Correct A
Q.006 If the protected members are to be made accessible only to the nearest subclass and no
further subclasses, which access specifier should be used in inheritance?
A The sub class should inherit the parent class privately
B The sub class should inherit the parent class as protected
C The sub class should inherit the parent class as public
D The sub class can use any access modifier
Correct A
Q.007 Except constructors, if all the members are defined in protected specifier then ___
A Instance of class can’t be created
B Instance of class can be created anywhere
C Instance of class can be created only in subclasses
D Instance of class can be created only in main() function
Correct B
Q.008 If protected inheritance is used then _
A Public members become public in subclass
B Protected members become public in subclass
C Protected members become protected in subclass
D Protected and Public members become protected in subclass
Correct D

AY 2020-21 SEM-II Page 7


Q.009 Which among the following is correct to call a private member from outside the class?
A object.memberfunction( parameters );
B object->memberfunction( parameters );
C object->memberfunction( parameteres); or object.memberfunction( parameters );
D Not possible
Correct D
Q.010 Which among the following is true?
A Private member functions can’t be overloaded
B Private member functions can be overridden
C Private member functions can’t be overloaded with a public member
D Private member function can’t be overridden
Correct D
Q.011 Which among the following is correct?
A Private specifier must be used before public specifier
B Private specifier must be used before protected specifier
C Private specifier must be used first
D Private specifier can be used anywhere in class
Correct D
Q.012 Which among the following can be used for outermost class access specifier in java?
A Private
B Public
C Default
D Default or Public
Correct D
Q.013 Which among the following for public specifier is false?
A The static members can’t be public
B The public members are available in other packages too
C The subclasses can inherit the public members privately
D There can be only one public class in java program
Correct A
Q.014 To create a pointer to a private data member of a class, outside the class, which among
the following is correct?
A Return the address of the private data member using a member function
B Access the private member using a pointer outside class
C Declare the member as pointer inside the class
D Not possible to create pointer to a private member
Correct A
Q.015 All the member functions of local classes are ___ _ by default.
A Static
B Inline

AY 2020-21 SEM-II Page 8


C Abstract
D Virtual
Correct C
Q.016 A static nested class is ____ class in behavior that is nested in another _ _ class.
A Top level, top level
B Top level, low level
C Low level, top level
D Low level, low level
Correct A
Q.017 What is the type of elements of array of objects?
A Class
B Void
C String
D Null
Correct A
Q.018 The Object array is created in ___
A Heap memory
B Stack memory
C HDD
D ROM
Correct A
Q.019 Can a super class object give reference to a subclass method?
A No, it is not possible
B Maybe, it is possible
C No, it’s not possible
D No, It’s not possible in few cases only

Correct C
Q.031 What is the role of a constructor in classes?
A To modify the data whenever required
B To destroy an object
C To initialize the data members of an object when it is created
D To call private functions from the outer world
Correct C
Q.032 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 9


A 5
B 55
C Error
D Segmentation Fault
Correct C
Q.033 How constructors are different from other member functions of the class?
A Constructor has the same name as the class itself
B Constructors do not return anything
C Constructors are automatically called when an object is created
D All of the mentioned
Correct D
Q.034 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 10


A B's Constructor called
B's Constructor called
B B's Constructor called
A's default constructor called
B's Constructor called
A's default constructor called
C A's default constructor called
B's Constructor called
A's default constructor called
B's Constructor called
D A's default constructor called
B's Constructor called
A's copy Constructor called
Correct C

Q.035 What is the role of destructors in Classes?


A To modify the data whenever required
B To destroy an object when the lifetime of an object ends

AY 2020-21 SEM-II Page 11


C To initialize the data members of an object when it is created
D To call private functions from the outer world
Correct B
Q.036 What is syntax of defining a destructor of class A?
A A(){}
B ~A(){}
C A::A(){}
D ~A(){};
Correct B
Q.037 In case of operator overloading, operator function must be _ _.
1. Static member functions
2. Non- static member functions
3. Friend Functions
A Only 2
B Only 1, 3
C Only 2 , 3
D All 1 , 2, 3
Correct C
Q.038 In case of binary operator overloading with member function, which of following
statement should be taken into consideration?
A Right hand operand must be object.
B Left hand operand must be object.
C Both the operands must be objects.
D All of these should be considered.
Correct B
Q.039 Given the following C++ code. How would you define the < operator for Box class so
that when boxes b1 and b2 are compared in if block the program gives correct result?

AY 2020-21 SEM-II Page 12


A bool operator<(Box b)
{
return this->capacity <b.capacity ? true : false;
}
B bool operator<(Box b)
{
return this->capacity >b.capacity ? true : false;
}
C bool operator<(Box b)
{
return b1 > b2 ? true : false;
}
D bool operator<(Box b)
{
return this <b ? true : false;
}
Correct A
Q.040 Which is the correct example of a unary operator?
A &

AY 2020-21 SEM-II Page 13


B ==
C -
D /
Correct C
Q.041 Which is called ternary operator?
A ?:
B &&
C |||
D ===
Correct A
Q.042 In case of inheritance where both base and derived class are having constructors, when
an object of derived class is created then_ .
A constructor of derived class will be invoked first
B constructor of base class will be invoked first
C constructor of derived class will be executed first followed by base class
D constructor of base class will be executed first followed by derived class
Correct D
Q.043 When a child class inherits traits from more than one parent class, this type of
inheritance is called ____ _ inheritance.
A Hierarchical
B Hybrid
C Multilevel
D Multiple
Correct D
Q.044 When a base class is privately inherited by the derived class, then_ .
A protected members of the base class become private members of derived class
B public members of the base class become private members of derived class
C both a and b
D only b
Correct C
Q.045 class X, class Y and class Z are derived from class BASE. This is____ inheritance.
A Multiple
B Multilevel
C Hierarchical
D Single
Correct C
Q.046 What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class student

AY 2020-21 SEM-II Page 14


{
public:
int rno , m1 , m2 ;
void get()
{
rno = 15, m1 = 10, m2 = 10;
}
};
class sports
{
public:
int sm;
void getsm()
{
sm = 10;
}
};
class statement:publicstudent,public sports
{
int tot,avg;
public:
void display()
{
tot = (m1 + m2 + sm);
avg = tot / 3;
cout<< tot;
cout<< avg;
}
};
int main()
{
statement obj;
obj.get();
obj.getsm();
obj.display();
}
A 3100
B 3010
C 2010
D 1010
Correct B
Q.047 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 15


A 1
B 0
C Segmentation Fault
D Error
Correct D
Q.048 What will be the output of the following C++ code?

AY 2020-21 SEM-II Page 16


A a: 1
B a: 0
C Error
D Segmentation fault
Correct A
Q.049 What will be the output of the following C++ code?

A Error

AY 2020-21 SEM-II Page 17


B Segmentation fault
C a: 1
D a: 0
Correct A
Q.050 When base class is derived in protected mode, then_ .
1. public members of base class become private members of derived class.
2. public members of base class become protected members of derived class.
3. public members of base class become public members of derived class.
4. protected members of base class become protected members of derived class.
5. protected members of base class become private members of derived class.
6. protected members of base class become public members of derived class.
A Only 1, 5
B Only 1, 6
C Only 2, 6
D Only 2, 4
Correct D

UNIT II MCQ

1. Which of the following is not a type of constructor?


A. Copy constructor

B. Friend constructor

C. Default constructor

D. Parameterized constructor
Answer: Option B

3. 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: Option B

4. Which of the following is not the member of class?


A. Static function

AY 2020-21 SEM-II Page 18


B. Friend function

C. Const function

D. Virtual function
Answer: Option B

5. 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: Option C

6. Which of the following term is used for a function defined inside a class?
A. Member Variable

B. Member function

C. Class function

D. Classic function
Answer: Option B

7. Which of the following concept of oops allows compiler to insert arguments in a function
call if it is not specified?
A. Call by value

B. Call by reference

C. Default arguments

D. Call by pointer
Answer: Option C

8. How many instances of an abstract class can be created?


A. 1

B.5

C. 13

D. 0

AY 2020-21 SEM-II Page 19


Answer: Option D

9. Which of the following cannot be friend?


A. Function

B. Class

C. Object

D. Operator function
Answer: Option C

11. A function that is called automatically each time an object is destroyed is a?


(a) Destructor
(b.) Destroyer
(c.) Remover
(d.) Terminator

Answer: Option a

13. True/False: A class can serve as base class for many derived classes.

Answer: True

14. When a class serves as base class for many derived classes, the situation is called:
a. polymorphism
b. hierarchical inheritance
c. hybrid inheritance
d. multipath inheritance

e. none of these

Answer: (b)

15. When two or more classes serve as base class for a derived class, the situation is known as
_ .

a) multiple inheritance
b) polymorphism

AY 2020-21 SEM-II Page 20


c) encapsulation

d) hierarchical inheritance
e) none of these

Answer: (a)
16. Which of the following statement is correct?
A. A constructor is called at the time of declaration of an object.

B. A constructor is called at the time of use of an object.

C. A constructor is called at the time of declaration of a class.

D. A constructor is called at the time of use of a class.

Answer: Option A

17. Which of the following functions are performed by a constructor?


A. Construct a new class
B. Construct a new object

C. Construct a new function

D. Initialize objects
Answer: Option D

21. Which of the following is correct about the statements given below?
All operators can be overloaded in C++.
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: Option B

22. What happens if the base and derived class contains definition of a function with same
prototype?
A. Compiler reports an error on compilation.

AY 2020-21 SEM-II Page 21


B. Only base class function will get called irrespective of object.

C. Only derived class function will get called irrespective of object.


D. Base class object will call base class function and derived class object will call derived
class function.
Answer: Option D

24. Which of the following is not a type of inheritance?


A. Multiple

B. Multilevel
C. Distributive

D. Hierarchical
Answer: Option C

25. Which of the following statements regarding inline functions is correct?


A. It speeds up execution.

B. It slows down execution.


C. It increases the code size.

D. Both A and C.
Answer: Option D

27. Which of the following operators cannot be overloaded?


A. []

B. ->
C. ?:

D. *
Answer: Option C

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


A. overload

B. operator
C. friend

AY 2020-21 SEM-II Page 22


D. override
Answer: Option B

30. Which inheritance type is used in the class given below?


class A : public X, public Y
{}
A. Multilevel inheritance
B. Multiple inheritance

C. Hybrid inheritance

D. Hierarchical Inheritance
Answer: Option B

32. Which of the following is an invalid visibility label while inheriting a class?
A. public
B. private

C. protected

D. friend
Answer: Option D

33. Which of the following provides a reuse mechanism?


A. Abstraction
B. Inheritance

C. Dynamic binding
D. Encapsulation
Answer: Option B

34. Which of the following statement is correct?


A. Class is an instance of object.
B. Object is an instance of a class.

C. Class is an instance of data type.


D. Object is an instance of data type.

AY 2020-21 SEM-II Page 23


Answer: Option B

35. When a function is defined inside a class, this function is called ………….
A) Inside function
B) Class function
C) Inline function
D) Interior function

Answer C) Inline function

36. Which of the following cannot be passed to a function?


A) Reference variable
B) Arrays
C) Class objects
D) Header files

Answer D) Header files

37. State true of false.


i) We cannot make the function inline by defining a function outside the class.
ii) A member function can be called by using its name inside another member function of the same
class, this is known as nesting of member function.
A) True, True
B) True, False
C) False, True
D) False, False
Answer C) False, True

38. Which of the following operators could be overloaded?


A) Size of
B) +
C) +=
D) ::

Answer B) +

39. Which of the following is true about the static member variable in C++.
i) It is initialized to zero when the first object of its class is created. Other initialization is also
permitted.
ii) It is visible only within the class, but its lifetime is the entire program.
A) i-True, ii-True
B) ii-False, ii-True
C) i-True, ii-False
D) i-False, iii-False

AY 2020-21 SEM-II Page 24


Answer B) ii-False, ii-True

40. Which of the following keywords are used to control access to a class member?
A) default
B) break
C) protected
D) goto

Answer C) protected

41. What will be the values of x, m and n after execution of the following statements?

Int x, m, n;
m=10;
n=15;
x= ++m + n++;

A) x=25, m=10, n=15


B) x=27, m=10, n=15
C) x=26, m=11, n=16
D) x=27, m=11, n=16

Answer C) x=26, m=11, n=16

42. 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 re usability of code
D) To extend the capabilities of a class

Answer C) To facilitate the reusability of code

43. A variable is defined within a block in a body of a function. Which of the following are true?
A) It is visible throughout the function.
B) It is visible from the point of definition to the end of the program.
C) It is visible from the point of definition to the end of the block.
D) It is visible throughout the block.

Answer D) It is visible throughout the block.

47. What is inheritance?


A. Inheritance allows one class to reuse the state and behavior of another class.
B. It deals with dangling pointers

AY 2020-21 SEM-II Page 25


C. It deals with void pointers
D. It is type of class declaration
Answer: Option A

48. Constructor is
A. A class automatically called whenever a new object of this class is created
B. A class automatically called whenever a new object of this class is destroyed
C. A function automatically called whenever a new object of this class is created
D. A function automatically called whenever a new object of this class is destroyed
Answer: Option C

51. What happens when we try to compile the class definition in following code snippet?

class Birds {};


class Peacock : protected Birds {};

A. It will not compile because class body of Birds is not defined.

B. It will not compile because class body of Peacock is not defined.

C. It will not compile because a class cannot be protectedly inherited from other class.

D. It will compile succesfully.

Answer: Option D

52. Which of the following statements is incorrect?


A. Friend keyword can be used in the class to allow access to another class.

B. Friend keyword can be used for a function in the public section of a class.

C. Friend keyword can be used for a function in the private section of a class.

D. Friend keyword can be used on main().

Answer: Option D

AY 2020-21 SEM-II Page 26


54. Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?
A. A class member and a class object.

B. A class object and a class.

C. A class and a member of that class.

D. A class object and a member of that class.

Answer: Option D

56. How can we make a class abstract?


A. By making all member functions constant.

B. By making at least one member function as pure virtual function.

C. By declaring it abstract using the static keyword.

D. By declaring it abstract using the virtual keyword.

Answer: Option B

57. Which of the following statements is correct when a class is inherited publicly?
A. Public members of the base class become protected members of derived class.

B. Public members of the base class become private members of derived class.

C. Private members of the base class become protected members of derived class.

D. Public members of the base class become public members of derived class.

Answer: Option D

58. Which of the following statements is correct about the constructors and destructors?

AY 2020-21 SEM-II Page 27


A. Destructors can take arguments but constructors cannot.

B. Constructors can take arguments but destructors cannot.

C. Destructors can be overloaded but constructors cannot be overloaded.

D. Constructors and destructors can both return a value.

Answer: Option B

59. Which of the following access specifies is used in a class definition by default?
A. Protected

B. Public

C. Private

D. Friend

Answer: Option C

60. Which of the following statement is correct with respect to the use of friend keyword inside a
class?
A. A private data member can be declared as a friend.

B. A class may be declared as a friend.

C. An object may be declared as a friend.

D. We can use friend keyword as a class name.

Answer: Option B

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

AY 2020-21 SEM-II Page 28


A. Default

B. Break

C. Protected

D. Asm

Answer: Option C

62. Which of the following is false with respect to inheritance?


[A] When a base class is privately inherited, public members of the base class become private
members of the derived class
[B] When a base class is publicly inherited, public members of the base class becomes public
members of derived class
[C] When a base class is privately inherited, a private member of base class becomes private
member of derived class
[D] When a base class is publicly inherited protected members of base class becomes protected
members of derived class
Answer: C. when a base class is privately inherited, a private member of base class becomes
private member of derived class
65. If a base class member access is public, and an inherited class accesses specifier is private,
which of the following statement is true ?
[A] The base class member can be accessed by derived class objects
[B] The base class members cannot be accessed by the derived class members
[C] The derived class members can be accessed by the base class objects
[D] None of above
Answer: A. The base class member can be accessed by derived class objects

69. What is meant by multiple inheritance?


[A] Deriving a base class from derived class
[B] Deriving a derived class from base class
[C] Deriving a derived class from more than one base class
[D] None of the mentioned

AY 2020-21 SEM-II Page 29


Answer: C. Deriving a derived class from more than one base class

71. what is Hybrid Inheritance?


[A] multiple inheritance
[B] multilevel inheritance
[C] multipath inheritance
[D] combination of a and b
[E] combination of a and c
Answer: D. combination of a and b

73.. What is required in inheritance to initialize the data members of the base class through derived
class?

A) Object declaration

B) Destructor

C) Constructor

D) Inheritance

Answer:C) Constructor

75. Which of the statements is true in a protected derivation of a derived class from a base class?

A) Private members of the base class become protected members of the derived class

B) Protected members of the base class become public members of the derived class

C) Public members of the base class become protected members of the derived class

D) Protected derivation does not affect private and protected members of the derived class

AY 2020-21 SEM-II Page 30


Answer:C) Public members of the base class become protected members of the derived
class

76. When the access specifier of the base class in the derived class definition is public, the base
class is ..

A) Publicly inherited

B) Protectedly inherited

C) Privately inherited

D) None of the above


Answer:A) Publicly inherited

79. The constructor and the destructor of a class are automatically invoked when memory is
allocated and deallocated to an ....

A) Data type

B) Copy constructor

C) Object

D) None of the above

Answer:C) Object

80. A pure virtual function is a virtual function that

A) has no body

B) returns nothing

C) is used in base class

D) both (A) and (C)

Answer:D) both (A) and (C)

AY 2020-21 SEM-II Page 31


81. A class defined within another class is

A) Nested Class

B) Inheritance

C) Containership

D) Encapsulation
Answer:A) Nested Class

82. Which variable stores the memory address of another variable?

A) Reference

B) Pointer

C) Array

D) None of the above

Answer:B) Pointer

83. Which of the following correctly declares an array?


a) int array[10];
b) int array;
c) array{10};
d) array array[10];

Answer:a
Explanation:Because array variable and values need to be declared after the datatype only.

84. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined

Answer:b
Explanation:Because the first element always starts at 0. So it is on 8 position.

AY 2020-21 SEM-II Page 32


85. What is a array?
a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same type placed in non-contiguous memory locations
d) None of the mentioned

Answer:a
Explanation:None.

86. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;

Answer:a
Explanation:The array location starts from zero, So it can accessed by array[6].

87. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;

Answer:d

88. What will be the output of this program?

#include <stdio.h>
using namespace std;
int array1[] = {1200, 200, 2300, 1230, 1543};
int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;
int main()
{
for (temp = 0; temp < 5; temp++) {
result += array1[temp];
}
for (temp = 0; temp < 4; temp++) {
result += array2[temp];
}
cout << result;
return 0;
}

AY 2020-21 SEM-II Page 33


a) 6553
b) 6533
c) 6522
d) 12200

Answer:b

Explanation:In this program we are adding the every element of two arrays. Finally we got output
as 6533.
Output:
$ g++ array.cpp
$ a.out
6533

89. What will be the output of the this program?

#include <stdio.h>
using namespace std;
int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 8; n++) {
result += array[n];
}
cout << result;
return 0;
}

a) 25
b) 26
c) 27
d) None of the mentioned

Answer:d
Explanation:We are adding all the elements in the array and printing it. Total elements in the
array is 7, but our for loop will go beyond 7 and add a garbage value.

91. What is the output of this program?

#include <stdio.h>
using namespace std;
int main()
{

AY 2020-21 SEM-II Page 34


char str[5] = "ABC";
cout << str[3];
cout << str;
return 0;
}

a) ABC
b) ABCD
c) AB
d) None of the mentioned

Answer:a
Explanation:We are just printing the values of first 3 values.
$ g++ array.cpp
$ a.out
ABC

99. Which among following is correct way of declaring object of a class ?

A. Classname Objectname;
B. Class Classname Objectname;
C. Class Classname Object Objectname;
D. Classname Object Objectname;

Answer: Option A

100. A Variable __ of void type.

A. May be declared

B. Can be initialized

C. Cannot be intialized

D. Cannot be declared

Answer: Option D

AY 2020-21 SEM-II Page 35


AY 2020-21 SEM-II Page 36
QN. QUESTION OPTION A OPTION B OPTION C OPTION D

1 Which of the following term is used for a Member Variable Member function Class function Classic function
function defined inside a class?
2 Classes are useful because they are removed from permit data to be hidden bring together all aspects can closely model
memory when not in use from other classes of an entity in one place objects in the real
world
3 Which member function of class cannot friend functions Private member functions Constant member Static member
modify its objects attributes ? functions functions
4 Which of the following is an abstract data int double string Class
type?
5 Which of the following statement is correct? Object is an instance of a Class is an instance of data Object is an instance of Class is an instance
class. type. data type. of object
6 Which of the following is correct about class class can have member class data members are Pointer to structure or class data members
and structure? functions while structure public by default while classes cannot be are private by
cannot. that of structure are private declared. default while that of
structure are public
by default.
7 What does your class can hold? Data Functions Both A & B None of the above
8 What is object in C++ ? Object is function of a Object is an instance of a Object is datatype of a Object is part of
class. class. class. syntax of a class
9 How many specifier are present as access 1 2 3 4
specifier in a class in C++?
10 Which operator is used to define the member : :: # None Of The
of a class externally? Mentioned
11 Which of the following is a valid class class A { int x; }; class B { } public class A { } object A { int x; };
declaration?

12 The fields in the class in c++ program are by protected private public none of the
default mentioned
13 What is class in c++ ? When you define a class, When you define a class, A. When you define a When you define a
you define a blueprint for you add more class, you define class, you make
a data type functionality. the logic. debugging.

14 ‘cin’ is __ a Class an Object a Package Namespace

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 37


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

15 Operators such as ....................... cannot be + ++ :: ==


overloaded.
16 Which of the following is the inequality != = == A) -->
operator?
17 The preprocessor directive always starts % # & “”
with the symbol
18 Which operator is used to define member : :: * Extern
function outside of a class in c++?
19 The if-else statement can be replaced by Bitwise operator * Conditional operator None of these
which operator? (?:)

20 The new operator returns a pointer to the creates a variable called obtains memory for a tells how much
variable new new variable memory is
available

21 Which of the following is the boolean | & && |&


operator for logical-and?
22 The operator that cannot be overloaded is ++ A) :: () A) ~

23 Which of the following is the correct := = equal ==


operator to compare two variables?

24 ::count means ----- Local version of the Global version of the Both local and global All of these
variable count variable count version of count
25 The scope resolution operator is a semicolon(;) a colon(:) two colons(::) a comma(,)

26 Which refrence modifier is used to define & $ # none of the


reference variable? mentioned

27 Which of the following is not a member- * ::* ->* ::


dereferencing operator?

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 38


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

28 Which operator is used to resolve the −> . * ::


scope of the global variable?
29 Which of the following operators allow :: ? :? %
defining the member functions of a class
outside the class?
30 What is the stored in the object obj in Memory address of NULL Any arbitrary pointer Garbage
following lines of code? allocated memory of
box obj; object.
31 Classes are useful, because they can closely model they permit data to be bring all aspects together none of these
objects in real world hidden from other classes as a one entity
32 In C++ the function contained in the class is member function procedure class function none of these
called __
33 _ _ is a special character used to mark the : ; # $
end of class.
34 Which of the following is called instance of function friend function object member variable
the class ?
35 The class holds _. functions data both A and B none of these
36 Choose the valid class declaration. class {} Classes {int a;} public class A {} none of these

37 Instead of the class if use struct then _ _. access in the public by access is private by default access is protected by none of these
default default
38 choose the correct statement. only data members are only member functions both data and member . the member
private are public functions can be public functions are private
39 Which of the following is not validity access public private protected extern
specifier in the class ?
40 A class cannot be _ _. virtual friend generic inline
41 What is the purpose of keyword inline? it allows one line function . it causes the replacement it indicates the function it tells compiler to
declaration of function calls by the declaration use that function in
code from the function the same source
code file
42 Which of the following is a valid inline public private protected extern
function 'myfun'?

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 39


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

43 inline void myfun() void myfun() inline inline:: void none of these
{//functon code} {//function code} myfun{//function code}
44 Following is a main benefit of the inline it decrease the size of the it simplifies the source it increases the speed of it removes
function/ program code the resulting program unnecessary
function
45 Following is a limit on inline function. inline function can not inline function has to inline function must have the compiler can
return a values return a value less than 10 lines of code choose to ignore an
inline directive.
46 When will you make a function inline? if that function is small . if the function is small if the function is not if the function is not
and not called frequently but called frequently small but called small and not called
frequently frequently
47 The fields in class of C++ program are _ _. . public private protected none of these
48 Which of the following keyword is used to const switch private for
control the access of data members of a class
?

49 What arrays in the C++? . A series of elements of A series of elements of A series of elements of A series of elements
same type placed in different type placed in same type placed in non- of different type
continuous block of continuous block of continuous block of placed in non-
memory memory memory continuous block of
memory
50 The memory address for array can be obtained a[0] address_of(a) a[1] a
using .
51 What is the output of the following code? 42 30 garbage value syntax error
#include <iostream>
using namespace std;
class Test
{
private
int array[]={0,2,4,6,8,10,12};
public:
void computer();
};
void Test::compute()

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 40


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

{
int result=0;
for (int i=0;i<7;i++)
{
result+=array[i];
}
cout<<result;
}
int main()
{
test obj;
obj.compute();
return();
}
52 The size of heap memory is _ _. 100 MB 1024 MB 1024 GB determined by size
of RAM and swap
memory
53 How will you pass the large objects in C++? using call by value using call by reference either a or b none of these
method method
54 Objects of the same class shres the values of global variables and static non static and static static variables, non static local and static
_ and maintain separate values for _. variables variables
55 Which of the member functions of class private member functions constant member functions friend function static member
cannot modify its objects attributes ? function
56 How many types of classes are there? 1 2 3 4
57 How to access object in the class? using ternary operator using direct member scope resolution operator none of these
access operator
58 Constructors are used . to build a user interface deallocate memory initialize newly created to construct
objects functions
59 Which of the following member is not public private protected both B and C
accessible using the direct member access
operator?
60 If different objects are created the separate data members member functions both A ans B none of these
memory space is created for .

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 41


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

61 The memory required by any objects is size of non static data order of data members Byte padding all of these
dependent upon following factors members of the class

62 Which of the following is correct way of Class_name object_name; object_name class_name class class_name class class_name
declaring object of a class ? object_name object object_name
63 What is the output of the following code? 10 constructor invoked syntax error none of these
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test(int x);
};
test::test(int x=10)
{
a=x;
cout<<"\n Constructor Invoked";
}
int main()
{
test obj1,*obj2;
return 0;
}
64 How many objects can be created by a single 1 2 3 as many as required
class?
65 The name of the constructor is . limited to 10 character same as the belonging main as per the
class name programmer's choice
66 What is the output of the following code? Constructor syntax error constructor copy constructor
#include <iostream> copy constructor copy constructor copy constructor
using namespace std; copy constructor constructor copy constructor
class test
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 42


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

private:
int a;
public:
test(int x);
test(test &);
};
test::test(int x=10)
{
a=x;
cout<<"\n CopyConstrustor";
}
int main()
{
test*obj1,*obj2;
obj1=new test (10);
obj2=new test(*obj1);
test *obj3;
obj3=new test(20);
return 0;
}

67 What is the output of the following code? 012 000 three garbage values syntax error
#include<iostream> .
using namespace std;
class test
{
private:
int a;
public:
test(int x)
void display();
};
test::test(int i)
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 43


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

a=i;
}
void test::display()
{
cout<<""<<a;
}
int main()
{
test obj[3];
obj[0].display();
obj[1].display();
obj[2].dispaly();
return 0;
}
68 What is the output of the following code? constructor constructor constructor destructor constructor constructor no output
#include<iostream> destructor destructor
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
cout<<"constructor";
}
~test()
{
cout<<"destructor";
}
};
int main()
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 44


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

test a[2];
return 0;
}
69 What is the output of the following code? 0 1 garbage value syntax error
#include<iostream>
using namespace std;
class test
{
private:
int a;
public:
test()
{
a=0;
count++;
}
void display()
{
cout<count;
}
};
int main()
{
test obj;
obj.display();
return 0;
}
70 What will be the output of the following syntax error nothing will be displayed Constructor destructor Constructor
code? constructor
class test
{
public:
test()
{cout< "constructor";}

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 45


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

~test()
{cout< "destructor";}
};
int main()
{
delete new test();
return 0;
}
71 The default constructor accepts _ one two three no
parameters.
72 If the default constructor is not defined then . it will cause syntax error it will cause runtime error the compiler will create none of these.
_ _ constructor for creating
an object
73 A class is not having default constructor but the desired object will get it will cause syntax error it will cause runtime error none of these
one parameterized constructor. created because compiler
We have created an object that needs zero will create an inplicit
argument constructor. What will happen in default constructor.
this case?.
74 The destructor is preceded by the symbol # ! ~ $
_
75 The constructors and destructors for an by making explicit call to when object enters and when inheritance occurs none of these
automatic object are invoked . constructor and destructor leaves its scope
functions
76 For copying the object of same class type default constructor dynamic constructor when inheritance occurs none of these
following type of constructor is defined
_
77 Which of the following is true about only I I,III and IV I and II I,II and III
constructor?
I. Constructor have same name as its class
name.
II. They constructors can be inherited
III. The constructor cannot be declared in
protected section.
IV. Constructor cannot return values.

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 46


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

78 Which of the following is not true about only I I and II I and III I,II and III
destructor?
I. It is preceded by dollar sign
II. It can be declared in private section
III. It can be parameterized
79 Object can be defined as _. attribute of class instance of a class member of a class none of these
80 The copy constructor _. creates an object from creates an object from an creates an object which is none of these
any object. object of same class pointer to copied object
81 For initializing the data members of class data members get creates an object from an creates an object which is none of these
_ _ is used. initialized automatically object of the same class. pointer to copied object
in C++
82 For initializing the data members of class _ data members get constructor destructor none of these
is used. initialized automatically
in C++
83 A class can have . all the constructors that only parameterized and only copy constructors only parameterized
are required copy constructors constructors
84 Which of the following statement is correct ?
A. constructors can have default parameters.
B. constructor cannot have default parameters.
C. constructor cannot have more than one
default parameters.
D. At the most 3 default parameters are
allowed for constructor.
ANSWER: A

85 Which constructor will execute in following constructor 1 constructor 2 constructor 3 syntax error
code?
class test{
public:
int a,b;
test(){a=b=1;}
test(int a){a=a;b=1;}
test(int a,int b){a=a;b=b;}
}

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 47


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

int main()
{
test obj(1,2);
return 0;
}

86 What value should destructor return ? status code that indicates pointer to class destructor does not return object of a class
that allocated memory for any value
object is freed.
87 Which of the following is nota type of default constructor parameterized constructor copy constructor public constructor
constructor?
88 Which of the following statement will invoke TEST T1(T2) T1=new Test(); T1=T2 none of these
copy constructor for class TEST?
89 Operator overloading is _. technique to work with technique which allows making new C++ giving new relevent
objects C++ to handle more than operators meaning to existing
one operators C++ operators
without changing
basis meaning
90 Operator function is created using _ allocator . constructor operator iterator
keyword.

91 How tp declare operator function ? operator function_name operator operator_sign() operator_sign none of these
92 Which of following operator cannot be + - :: []
overload?
93 Operator function must be _ . only 1 1 and 3 2 and 3 All 1,2 and 3
1. Non-static member function 2. Static
function 3. friend function
94 In C++ _ _ operator is used for dynamic Scope resolution operator conditional operator new arithmetic operator
memory allocation. +
95 While overloading binary operator using Zero argument one argument two arguments it depends upon the
member function it requires . operator to be
overloaded
96 What will be the output of the following 30 3 00 11 22 22 11
code?

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 48


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

vector vector::operator +(vector obj)


{
vector temp;
temp.p=p+obj.p;
temp.q=q+obj.q;
return(temp);
}
void main()
{
vector a(10,20);
vector b(1,2);
vector c,
c=a+b;
cout<<c.p<<""and<<c.q;
}
97 Reusability of code is achieved by _ _. encapsulation polymorphism inheritance none of these
98 The derived class is derived from _ _. .main base class friend class

99 Which of the following is a type of data members member function . both A and B none of these
inheritance?

100 Which of the following is a type of single inheritance and single and multiple Single ,multiple, single, multiple,
inheritance? multilevel inheritance inheritance multilevel inheritance multilevel
,hierarchical and
hybrid inheritance
]
101 In relationship an object of derived class encapsulation . polymorphism inheritance none of these
can also be treated as an object of its base
class.
102 For deriving the child class from the base :: : ; ->
class which symbol is used?
103 What will be output of following code? syntax error 55.55 10 10 55.55 55.55
Class A
{

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 49


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

public:
A(int n)
{
cout<<n;
}
};
class B:public A
{
B(int n,double d):A(n)
{
cout<<""<<d;
}
};
int main()
{
B b(10 ,55.55);
return 0;
}
104 What will be the output of the following 10 A 11.11 A 11.11 10 A 11.11
code?
Class A
{
public:
A(int x)
{
cout<<x;
}
};
class B: public A
{
public:
B(int x,char y):A(x)
{
cout<<" "<<y;

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 50


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

}
};
class C:public B
{
public:
C(int x,char y,double z) :B(x,y)
{
cout<<" "<<z;
}
};
int main()
{
C c(10,'A’,11.11);
return 0;
}
105 When an object of derived class is instantiated base class constructor derived class constructor not allowed to instantiate none of these
the _ is called explicitly or implicitly. derived class constructor
106 Class b is derived from class A then it is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
called____
107 Class C is derived from class B and class B is Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
derived from class A then it is called .
108 Class D is derived from class Base 1 and Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Class Base 2 then it is called _ _.
109 Class A,B,ansC are derived from class Single inheritance Multiple inheritance Multilevel inheritance Hybrid inheritance
Base2then it is called __ .
110 What will be the output of the following 100 0 syntax error none of these
code?
class A
{
private:
int x;
protected:
int y;
public:

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 51


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

int z;
};
class B:public A
{
};
int main()
{
B b;
b.x=100;
cout<<b.x;
return 0;
}
111 When base class is derived in protected mode only 1 ,5 only 2,4 only 1,6 only 2,6
then .
1. public members of base class become
private members of derived class.
2. public member of the base class become
proctected members of derived class
3. public members of base class become
public members of derived class.
4. protected members of base class become
proctected members of derived class.
5. protected members of base class become
private members of derived class.
6. protected members of base class become
public members of derived.
112 When deriving a class with public inheritance, Public, public Public, private public ,protected protected ,private
public members of the base class become
members of the derived class and protected
members of the base class become
members of the derived class.
113 If the class is derived using protected mode public members private members protected none of these
then public members of the base class become
_ of derived class.

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 52


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

114 If the class is derived using protected mode public members private members protected none of these
then protected members of the base class
become _ of derived class.
115 If the class is derived using protected mode public members private members protected none of these
then private members of the base class
become _ of derived class.
116 What will be the output of the following x=10,y=20,z=30 error for x,y=20,z=30 error for x and y,z=30 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:protected A
{
public:
void display()
{
x=10;
y=20;
z=30;
}
};
117 If a class is derived using private mode then public members private members protected none of these
public members of base class become _ of
derived class.

118 If a class is derived using private mode then public members private members protected none of these
protected mode members of base class
become _ _ of derived class

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 53


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

119 If a class is derived using private mode then public members private members protected none of these
private mode members of base class become
_ _ of derived class

120 What will be the output of the following x=100,y=200,z=300 error for x,y=200,z=300 error for x and y,z=300 error for x,y and z
code?
class A
{
private:
int x;
protected:
int y;
public:
int z;
};
class B:private A
{
public:
void display()
{
x=100;
y=200;
z=300;
}
};
121 What will be the output of the following The value of x,y and z are error for assigment of x error for assignment of x error for accessibilty
code? assigned as 10,20,30 and y of display ()
class A respectively function
{
private:
int x;
protected:
int y;

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 54


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

public:
int z;

void display()
{
x=10;
y=20;
z=30;
}
};
class B:private A
{

};
int main()
{
B b;
b.display();return 0;
}
122 During class inheritance if the visibility mode public private protected none of these
of derivation is not specified then the default
visibility mode is _ .

123 What is the difference between protected and private member is not protected member is both are inheritable but both are inheritable
private access specifier ? inhertiable and not inheritable and also private is accessible inthe but protected is not
accessible in derived accessible in derived class derived class accessible in the
class derived class.
124 If a derived class is struct then its visibiltiy public private protected . cannot inherit
mode is _ . structure
125 The constructors for both derived and base only the constructor of only the constructor of the constructor of base the constructor of
class are defined .using the main the object off derived class will be base class will be invoked. class will be invoked and derived class will be
derived class is created . invoked then the constructor of invoked and then the
In such a situation _. derived class will be constructor of base
invoked class will be invoked

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 55


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

126 What will be the output of the following base class constructor derived class constructor base class constructor derived class
code? derived class constructor constructor base
class A class constructor
{
public:
A()
{
cout<<"base class
construtor";
}
};
class B:public A
{
public:
B()
{
cout<<"Derived Class
Constructor";
}
};
int main()
{
B b;
return 0;
}

127 If we define a base class constructor with optional compusory depends upon the it will generate
arguments then it is _ for derived class to compiler syntax error because
have constructor and pass argument to base paramerized
class constructor. constructor is not
allowed in base class
128 What will be the output of the following . B_constructor B_constructor B_constructor Run time error
code? D_constructor D_constructor B_destructor
Class A D_destructor B_destructor D_constructor D_

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 56


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

{ B_destructor D_constructor destructor


public:
A()
{
cout<<"B_Constructor";
}
~A()
{
cout<<"B_Destructor";
}
};
int main()
{
B b;
return 0;
}

129 Which of the following is/are valid ways . int *p = new int(100); int *p; p = new int; *p = int *p = NULL; p = All of these
to allocate memory for an integer by 100; new int; *p=100;
dynamic memory allocation in CPP?
130 During dynamic memory allocation in False NULL Zero None of these
CPP, new operator returns _
value if memory allocation is
unsuccessful.
131 When the memory spaces for the member when the objects are when the class are when member All of these
functions are allocated? created created functions are defined as
a part of class
132 Why separate memory locations are member variables hold each object in the class Both a,b none of these
essential for an object different data values for has separate member
different objects function

133 The amount of memory allocated for an amount of memory amount of memory amount of memory amount of memory
object is equal to required by member required by data required by both data required by the

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 57


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

functions of that class members of that class members and data class
functions
134 All the objects of a class share the same data members member functions both data members and None of these
copy of member function
135 How will you free the memory allocated delete(p) delete p delete(int p) delete (p,0)
by the following program?
#include <iostream>
using namespace std
int main()
{
int *p;
p=new int;
return 0;
}
136 When the memory spaces for the data when the class is when the object of the when the member None of these
member are allocated? specified class is declared function is declared
137 How much memory will be allocated to 8Bytes 7Bytes 6Bytes No memory will
the object obj1 of the following class? be allocated
class test
{
float a;
int b;
char c;
}
int main()
{
test obj1;
return 0;
}

138 What are arrays in the C++? . A series of elements A series of elements of A series of elements of A series of

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 58


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

of same type placed in different type placed in same type placed in elements of
continuous block of continuous block of non-continuous block different type
memory. memory of memory placed in non-
continuous block
of memory.
139 The memory address for array can be a[0] address_of(a) a[1] a
obtained using _ _.
140 Which of the following are characteristics The array contains all All the elements of the The name of the array All of the above
of array? the elements of same array share the same represents the address
data type name and then can be of the first element of
distinguished from one an array
another by index
141 How will you pass the large objects in using call by value using call by reference either a or b none of these
C++? method method
142 Which of the following correctly declares int array[10]; int array; array{10}; array array[10];
an array?
143 What is the index number of the last 9 8 0 Programmer-
element of an array with 9 elements? defined
144 The process of storing the elements in an initialization of array declaration of array finalization of array none of the above
array is called as
145 Which of the following correctly declares ABC array[10]; ABC array; array{10}; array array[10];
an array of objects for a class ABC?
146 How much memory will be allocated to 10Bytes 20Bytes 40Bytes No memory is
the object obj1 in the following code? allocated
#include<iostream>
using namespace std;
class student
{
int age;
int roll_no;
public:

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 59


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

………
....……
};
int main()
{
student s[10];
………..
………..
return 0;
}
147 What will be the output of the following 30and3 0and0 11and 22 22and11
code?
vector vector::operator+(vector obj)
{
vector temp;
temp.p=p+obj.p;
temp.q=q+obj.q;
return (temp);
}
int main()
{
vector a(10,20);
vector b(1,2);
vector c;
c=a+b;
cout<<c.p<<”and”<<c.q;
return 0;
}
148 Which of the following statements are only 1 and 2 only 3 and 4 All of the above None of the above
true for operator overloading?
1. Only existing operators can be

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 60


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

overloaded
2. The overloaded operator must have at
least one operand that is of user defined
type.
3. Overloaded operators follow the syntax
rules of the original operators.
4. Binary arithmetic operators such as +,-
,* and / must explicitly return a value.

149 Which is the correct function prototype complex complex complex complex
declaration for overloading the ‘+’ operator+(complex); operator++(complex); operator+(complex) operator(complex);
operator in class ‘complex’?
150 Inheritance is ............... in nature. Intransitive Transitive Both (a) & (b) None of the above

151 The result of the following statement is ans=7, y=7 ans=8,y=7 ans=8,y=8; none of the above
int y = 7;
int ans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;
152 What is the output of the following code? Error The result of addition The result of addition The result of
#include<iostream> is:16 is:sum(); addition is:
using namespace std;
class test
{
int a,b;
public:
test(int x, int y)
{
a=x; b=y;
}
int sum();

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 61


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

void display();
};
int test::sum()
{
return a+b;
}
void test::display()
{
cout<<”\nThe result of addition
is:”<<sum();
}
void main()
{
test obj1(7,9);
obj1.display();
return 0;
}
153 A constructor function is ___ A friend function to a A member function with A non-member None of the above
class the same name as its function
class
154 A constructor function is generally In the public section of In the private section of In the protected section None of the above
defined __ a class a class of a class
155 A class having no public constructors is A private class A public class An abstract class None of the above
__
156 If a constructor function is defined in The object cannot be Only member functions Both (a) & (b) None of the above
private section of a class, then created and friends may declare
__ objects of the class
157 A constructor with no argument is Default constructor Parameterized Copy constructor None of the above
__ _ constructor

158 If arguments are provided to a constructor Default constructor Copy instructor Parameterized None of the above

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 62


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

function, then it becomes constructor


__

159 The parameterized constructor Needs initial values as Can be invoked Can be invoked None of the above
__ arguments during explicitly only implicitly only
creation of an object
160 Given a class named Book, which of the Book ( ) { } Book ( Book b) { } Book ( Book &b) { } Book (char*
following is not a valid constructor? author, char* title)
{}
161 Which of the following statements A constructor may be Constructor can have Member functions may None of the above
regarding constructor is false? defined static default arguments be invoked from within
a constructor
162 A destruction function Takes no argument and Has name similar to that Is used to destruct an All of the above
has no return type not of class, preceded by object, constructed
even void tilde(~) symbol through constructor
function
163 Destructors are called __ _ in the same order of in the reverse order of in any random order none of the above
constructor calls constructor calls

164 Constructors are used _ to build a user interface deallocate memory initialize newly created to construct
objects functions
165 If a default constructor is not defined then it will cause syntax ) it will cause runtime the complier will create none of these
__ . error error constructor for creating
an object
166 How many constructors can a class have? 0 1 2 any number
167 Which of the following is not the They should be They do not have return They can not be They can be
characteristic of constructor. declared in the public type. inherited virtual.
section.
168 In which case is it mandatory to provide a Almost in every class Class for which two or Class for which copy Class whose
destructor in a class? more than two objects constructor is defined objects will be
will be created created

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 63


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

dynamically
169 Class function which is called Constructor Destructor Friend function Inline function.
automatically as soon as the object is
created is called as __
170 Complement of the constructor is Overloading Inheritance Polymorphism Destructor
171 If c1 and c2 are objects of class complex Sum is : 12+i2 Sum is : 5+i4 Sum is : 7-i2 syntax error
and c1=5+i4 and c2=7-i2 then what is the
output of the following program?
#include <iostream>
#include <math.h>
using namespace std;

class complex
{
int real,img;
public:

void display()
{
if(img>0)

cout<<real<<"+i"<<img<<endl;
else
{
cout<<real<<"-i"<<-
img<<endl;
}
}
complex operator+(complex);
};
complex complex :: operator+(complex c2)
{
complex sum;

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 64


QN. QUESTION OPTION A OPTION B OPTION C OPTION D

sum.real = real+c2.real;
sum.img = img+c2.img;
return (sum);
}
int main()
{
complex c1,c2,ans;
ans = c1+c2;
cout<<"Sum is : ";
ans.display();
return 0;
}
172 An array name is a _____ Subscript formal parameter memory address prototype

173 If an array is declared as 3, 2 0, 2 3, 0 0, 4


int a[4] = {3, 0, 1, 2}, then values
assigned to a[0] & a[4] will be ___ _

174 Declaration of a pointer reserves memory for the object for the pointer both for the object and None of these.
space the pointer
175 Identify the operator that is NOT used -> & * >>
with pointers
176 An array element is accessed using a FIFO approach an index number the operator member name
177 The address of a variable temp of type *temp &temp float& temp float temp&
float is
178 Identify the correct sentence we cannot create the we can create the Array we can use reference to none of the
regarding inequality between reference array of reference. of reference reference mentioned
and pointer.
179 Functions can return_ _ Arrays References Objects All of above

OOP_MCQ_UNIT_2 PVG’s COET,PUNE Page 65


Subject: Object Oriented Programming Using CPP

Question bank for online exam

Classes and Objects:

1. Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function

2.Classes are useful because they


[A] are removed from memory when not in use
[B] permit data to be hidden from