0% found this document useful (0 votes)
265 views

C ++

This document contains 34 multiple choice questions about object-oriented programming concepts in C++. Each question is followed by the answer and an explanation is provided. The questions cover topics such as classes, inheritance, polymorphism, encapsulation, and other OOP concepts in C++.

Uploaded by

rathai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
265 views

C ++

This document contains 34 multiple choice questions about object-oriented programming concepts in C++. Each question is followed by the answer and an explanation is provided. The questions cover topics such as classes, inheritance, polymorphism, encapsulation, and other OOP concepts in C++.

Uploaded by

rathai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 127

1. Which of the following type of class allows only one object of it to be created?

A.Virtual class
B. Abstract class
C. Singleton class
D.Friend class

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report
4. Which of the following is not the member of class?
A.Static function
B. Friend function
C. Const function
D.Virtual function

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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


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

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

9. Which of the following cannot be friend?


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

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

10. Which of the following concepts of OOPS means exposing only necessary information to
client?
A.Encapsulation
B. Abstraction
C. Data hiding
D.Data binding

Answer: Option C

12. cout is a/an __________ .


A.operator
B. function
C. object
D.macro

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

13. Which of the following concepts provides facility of using object of one class inside another
class?
A.Encapsulation
B. Abstraction
C. Composition
D.Inheritance

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

14. How many types of polymorphisms are supported by C++?


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

Answer: Option B

Explanation:

The two main types of polymorphism are run-time (implemented as inheritance and virtual
functions), and compile-time (implemented as templates).
View Answer Discuss in Forum Workspace Report

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


A.int
B. double
C. string
D.Class
Answer: Option D

16. Which of the following concepts means adding new components to a program as it runs?
A.Data hiding
B. Dynamic typing
C. Dynamic binding
D.Dynamic loading

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

18. Which of the following correctly describes overloading of functions?


A.Virtual polymorphism
B. Transient polymorphism
C. Ad-hoc polymorphism
D.Pseudo polymorphism

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

19. Which of the following approach is adapted by C++?


A.Top-down
B. Bottom-up
C. Right-left
D.Left-right

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

20. Which of the following is correct about function overloading?


A.The types of arguments are different.
B. The order of argument is different.
C. The number of argument is same.
D.Both A and B.

Answer: Option D

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

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

22. Which of the following concepts means wrapping up of data and functions together?
A.Abstraction
B. Encapsulation
C. Inheritance
D.Polymorphism

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

23. Which of the following concepts means waiting until runtime to determine which function to
call?
A.Data hiding
B. Dynamic casting
C. Dynamic binding
D.Dynamic loading

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

24. How "Late binding" is implemented in C++?


A.Using C++ tables
B. Using Virtual tables
C. Using Indexed virtual tables
D.Using polymorphic tables

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

25. Which of the following operator is overloaded for object cout?


A.>>
B. <<
C. +
D.=

Answer: Option B

26. Which of the following is the correct class of the object cout?
A.iostream
B. istream
C. ostream
D.ifstream
Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

27. Which of the following cannot be used with the keyword virtual?
A.class
B. member functions
C. constructor
D.destructor

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

29. Which of the following problem causes an exception?


A.Missing semicolon in statement in main().
B. A problem in calling function.
C. A syntax error.
D.A run-time error.

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report
30. Which one of the following options is correct about the statement given below? The compiler
checks the type of reference in the object and not the type of object.
A.Inheritance
B. Polymorphism
C. Abstraction
D.Encapsulation

Answer: Option B

31. Which of the following is the correct way of declaring a function as constant?
A.const int ShowData(void) { /* statements */ }
B. int const ShowData(void) { /* statements */ }
C. int ShowData(void) const { /* statements */ }
D.Both A and B

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

32. Which of the following concepts is used to implement late binding?


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

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

33. Which of the following statement is correct?


A.C++ allows static type checking.
B. C++ allows dynamic type checking.
C. C++ allows static member function be of type const.
D.Both A and B.
Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

34. Which of the following factors supports the statement that reusability is a desirable feature of
a language?
A.It decreases the testing time.
B. It lowers the maintenance cost.
C. It reduces the compilation time.
D.Both A and B.

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

35. 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: Option A

36. Which of the following is a mechanism of static polymorphism?


A.Operator overloading
B. Function overloading
C. Templates
D.All of the above

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report
37. Which of the following is correct about the statements given below?

1. All operators can be overloaded in C++.


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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

38. What happens if the base and derived class contains definition of a function with same
prototype?
A.Compiler reports an error on compilation.
B. Only base class function will get called irrespective of object.
C. Only derived class function will get called irrespective of object.
Base class object will call base class function and derived class object will call derived
D.
class function.

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

39. Which of the following are available only in the class hierarchy chain?
A.Public data members
B. Private data members
C. Protected data members
D.Member functions

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report
40. Which of the following is not a type of inheritance?
A.Multiple
B. Multilevel
C. Distributive
D.Hierarchical

Answer: Option C

41. Which of the following operators cannot be overloaded?


A.[]
B. ->
C. ?:
D.*

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

42. In which of the following a virtual call is resolved at the time of compilation?
A.From inside the destructor.
B. From inside the constructor.
C. From inside the main().
D.Both A and B.

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

44. Which one of the following is the correct way to declare a pure virtual function?
A.virtual void Display(void){0};
B. virtual void Display = 0;
C. virtual void Display(void) = 0;
D.void Display(void) = 0;

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

45. Which of the following header file includes definition of cin and cout?
A.istream.h
B. ostream.h
C. iomanip.h
D.iostream.h

Answer: Option D

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


A.overload
B. operator
C. friend
D.override

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

47. What will happen if a class is not having any name?


A.It cannot have a destructor.
B. It cannot have a constructor.
C. It is not allowed.
D.Both A and B.

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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

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


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

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report
50. Which of the following is an invalid visibility label while inheriting a class?
A.public
B. private
C. protected
D.friend

Answer: Option D

51. Which one of the following options is correct?


A.Friend function can access public data members of the class.
B. Friend function can access protected data members of the class.
C. Friend function can access private data members of the class.
D.All of the above.

Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

52. Which of the following statements is correct in C++?


A.Classes cannot have data as protected members.
B. Structures can have functions as members.
C. Class members are public by default.
D.Structure members are private by default.

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

53. Which of the following is used to make an abstract class?


A.Declaring it abstract using static keyword.
B. Declaring it abstract using virtual keyword.
C. Making at least one member function as virtual function.
D.Making at least one member function as pure virtual function.
Answer: Option D

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

54. Which of the following access specifier is used as a default in a class definition?
A.protected
B. public
C. private
D.friend

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

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


A.A static member function can access only static data members of a class.
B. A static data member is shared among all the object of the class.
C. A static data member can be accessed directly from main().
D.Both A and B.

Answer: Option D

56. Which of the following provides a reuse mechanism?


A.Abstraction
B. Inheritance
C. Dynamic binding
D.Encapsulation

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.


View Answer Discuss in Forum Workspace Report

57. 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: Option B
1) Which of the following is not used to seek a file pointer?

a. ios::cur
b. ios::set
c. ios::end
d. ios::beg
Answer Explanation
ANSWER: ios::set

Explanation:
No explanation is available for this question!

2) 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
Answer Explanation
ANSWER: NULL

Explanation:
No explanation is available for this question!

3) We can create objects of the abstract class.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!
4) Which of the followings is/are pointer-to-member declarator?

a. ->*
b. .*
c. ::*
d. both a and b
Answer Explanation
ANSWER: ::*

Explanation:
No explanation is available for this question!

5) Default value of static variable is_____ .

a. 0
b. 1
c. Garbage value
d. Compiler dependent
Answer Explanation
ANSWER: 0

Explanation:
No explanation is available for this question!

6) ________ are used to format the data display in CPP.

a. Iterators
b. Punctuators
c. Manipulators
d. Allocators
Answer Explanation
ANSWER: Manipulators

Explanation:
No explanation is available for this question!

7) Reusability of the code can be achieved in CPP through ______ .

a. Polymorphism
b. Encapsulation
c. Inheritance
d. Both a and c
Answer Explanation
ANSWER: Inheritance
Explanation:
No explanation is available for this question!

8) By default, members of the class are ____________ in nature.

a. protected
b. private
c. public
d. static
Answer Explanation
ANSWER: private

Explanation:
No explanation is available for this question!

9) class TEST
{
private:
int roll_no;
public:
int age;
char name[20];
private:
int grade;
protected:
char gender[20];
private:

private:
int m1, m2, m3;
};

In general view, is this class definition valid?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!
10) Which of the following is CPP style type-casting?

a. per = total/(float)m
b. per = total/float(m)
c. per = (float)total/m
d. None of these
Answer Explanation
ANSWER: per = total/float(m)

Explanation:
No explanation is available for this question!

11) If a program uses Inline Function, then the function is expanded inline at
___________.

a. Compile time
b. Run time
c. Both a and b
d. None of these
Answer Explanation
ANSWER: Run time

Explanation:
No explanation is available for this question!

12) In CPP, the size of the character array should be one larger than the number of
characters in the string.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

13) 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. Only 1,2
e. All of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!

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

a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()
c. :: , . , .* , ?:
d. :: , ->, * , new, delete
Answer Explanation
ANSWER: :: , . , .* , ?:

Explanation:
No explanation is available for this question!

15) Static variable in a class is initialized when _____ .

a. every object of the class is created.


b. last object of the class is created.
c. first object of the class is created.
d. No need to initialize static variable.
Answer Explanation
ANSWER: first object of the class is created.

Explanation:
No explanation is available for this question!

16) To perform File I/O operations, we must use _____________ header file.

a. < ifstream>
b. < ofstream>
c. < fstream>
d. Any of these
Answer Explanation
ANSWER: < fstream>

Explanation:
No explanation is available for this question!
17) An exception is thrown using _____________ keyword in CPP.

a. throws
b. throw
c. threw
d. Thrown
Answer Explanation
ANSWER: throw

Explanation:
No explanation is available for this question!

18) Which of the followings is/are not a manipulator/s ?

1. flush
2. base
3. ends
4. oct
5. bin
6. skipws

a. Only 1, 6
b. Only 1,4,6
c. Only 1,3,6
d. Only 2,5
Answer Explanation
ANSWER: Only 2,5

Explanation:
No explanation is available for this question!

19) 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
Answer Explanation
ANSWER: Compiler provides its default constructor to build the object.

Explanation:
No explanation is available for this question!

20) Is it mandatory to invoke/call a constructor for creating an object?


a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

21) Members of the class can be declared with auto, extern or register storage classes.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

22) C structure differs from CPP class in regards that by default all the members of the
structure are __________ in nature.

a. private
b. protected
c. public
d. None of these
Answer Explanation
ANSWER: public

Explanation:
No explanation is available for this question!

23) Which of the following best defines the syntax for template function ?

a. Template
b. Template return_type Function_Name(Parameters)
c. Both a and b
d. None of these
Answer Explanation
ANSWER: Both a and b

Explanation:
No explanation is available for this question!

24) Generic pointers can be declared with__________ .

a. auto
b. void
c. asm
d. None of these
Answer Explanation
ANSWER: void

Explanation:
No explanation is available for this question!

25) 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 Explanation
ANSWER: 1,4,5

Explanation:
No explanation is available for this question!

1) Which of the following are true about static member function?

1. They can access non-static data members.


2. They can call only other static member functions.
3. They can access global functions and data.
4. They can have this pointer.
5. They cannot be declared as const or volatile.

a. Only 2
b. Only 2,5
c. Only 2,3,4,5
d. Only 2 , 3 , 5
e. All of these
Answer Explanation
ANSWER: Only 2 , 3 , 5

Explanation:
No explanation is available for this question!

2) Static variable must be declared in public section of the class.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

3) By default, if a function with minimum lines of code is declared and defined inside the
class becomes Inline function.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

4) class X, class Y and class Z are derived from class BASE. This is ______ inheritance.

a. Multiple
b. Multilevel
c. Hierarchical
d. Single
Answer Explanation
ANSWER: Hierarchical

Explanation:
No explanation is available for this question!

5) 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
Answer Explanation
ANSWER: Only 2, 4

Explanation:
No explanation is available for this question!

6) Can we have overloading of the function templates?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

7) Streams that will be performing both input and output operations must be declared as
class _________ .

a. iostream
b. fstream
c. stdstream
d. Stdiostream
Answer Explanation
ANSWER: fstream

Explanation:
No explanation is available for this question!
8) Exception handlers are declared with ____________ keyword.

a. Try
b. catch
c. throw
d. Finally
Answer Explanation
ANSWER: catch

Explanation:
No explanation is available for this question!

9) 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
Answer Explanation
ANSWER: Only 1, 4

Explanation:
No explanation is available for this question!

10) Static variable declared in a class are also called_________ .

a. instance variable
b. named constant
c. global variable
d. class variable
Answer Explanation
ANSWER: class variable

Explanation:
No explanation is available for this question!

11) Which of the following operator is used to release the dynamically allocated memory
in CPP?

a. remove
b. free
c. delete
d. both b and c
Answer Explanation
ANSWER: delete

Explanation:
No explanation is available for this question!

12) Which of the following is not a false statement about new operator?

a. It can’t be overloaded.
b. It returns garbage value when memory allocation fails.
c. It automatically computes the size of the data object.
d. All of these
Answer Explanation
ANSWER: It automatically computes the size of the data object.

Explanation:
No explanation is available for this question!

13) Private members of the class are accessible only to the members of the same class.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

14) Run time polymorphism can be achieved with______ .

a. Virtual Base class


b. Container class
c. Virtual function
d. Both a and c
Answer Explanation
ANSWER: Virtual function

Explanation:
No explanation is available for this question!

15) To create an output stream, we must declare the stream to be of class ___________ .

a. ofstream
b. ifstream
c. iostream
d. None of these
Answer Explanation
ANSWER: ofstream

Explanation:
No explanation is available for this question!

16) Catch handler can have multiple parameters.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

17) Inline functions may not work ______ .

1. If function contain static variables.


2. If function contain global and register variables.
3. If function returning value consists looping construct(i.e. for, while).
4. If inline functions are recursive.
5. If function contains const value.

a. Only 1,4,5
b. Only 2,3,5
c. Only 1,3,4
d. All of these
Answer Explanation
ANSWER: Only 1,3,4
Explanation:
No explanation is available for this question!

18) Which of the followings is/are not false about friend function ?

1. It can be called / invoked with class object.


2. It has objects as arguments.
3. It can have built-in types as arguments.
4. It must declared only in public part of a class.
5. It does not have this pointer as an argument.

a. Only 2,4
b. Only 1,2,5
c. Only 2,3,5
d. All of these
Answer Explanation
ANSWER: Only 2,3,5

Explanation:
No explanation is available for this question!

19) Predict the output:

int x = 786;
cout << setfill(‘*’) << setw(6) << x;

a. 786***
b. **786
c. ***786
d. ******
Answer Explanation
ANSWER: ***786

Explanation:
No explanation is available for this question!

20) Default return type of functions in CPP is ____ .

a. void
b. long
c. char
d. Int
Answer Explanation
ANSWER: Int

Explanation:
No explanation is available for this question!

21) Default values for a function are need to be specified from left to right only.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

22) 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
Answer Explanation
ANSWER: private

Explanation:
No explanation is available for this question!

23) The derivation of Child class from Base class is indicated by ____ symbol.

a. ::
b. :
c. ;
d. |
Answer Explanation
ANSWER: :

Explanation:
No explanation is available for this question!
24) If we have object from fstream class, then what is the default mode of opening the file?

a. ios::in|ios::out
b. ios::in|ios::out|ios::trunc
c. ios::in|ios::trunc
d. Default mode depends on compiler
Answer Explanation
ANSWER: Default mode depends on compiler

Explanation:
No explanation is available for this question!

25) __________ is return type of is_open() function.

a. int
b. bool
c. float
d. char *
Answer Explanation

ANSWER: bool

1) Public data members and member functions of the class are accessible ONLY to the
member functions of that class.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

2) Only functions of the class can access the data of the class and they(functions) provides
the interface between data, objects and the program. This kind isolation of the data from
direct access by the program is called _______________ .

a. Data Abstraction
b. Data Hiding
c. Data Binding
d. Data Encapsulation
Answer Explanation
ANSWER: Data Hiding

Explanation:
No explanation is available for this question!

3) A Constructor that does not have any parameters is called____________ Constructor.

a. Custom
b. Dynamic
c. Static
d. Default
Answer Explanation
ANSWER: Default

Explanation:
No explanation is available for this question!

4) If we have object from ofstream class, then default mode of opening the file is _____ .

a. ios::in
b. ios::out
c. ios::in|ios::trunc
d. ios::out|ios::trunk
Answer Explanation
ANSWER: ios::out|ios::trunk

Explanation:
No explanation is available for this question!

5) _______________ is a member function that is declared within a base class and


redefined by derived class.

a. virtual function
b. static function
c. friend function
d. const member function
Answer Explanation
ANSWER: virtual function

Explanation:
No explanation is available for this question!

6) Syntax for Pure Virtual Function is ______________ .

a. virtual void show()==0


b. void virtual show()==0
c. virtual void show()=0
d. void virtual show()=0
Answer Explanation
ANSWER: virtual void show()=0

Explanation:
No explanation is available for this question!

7) Logical expressions produce ____________ type results.

a. explicit
b. garbage
c. bool
d. static
Answer Explanation
ANSWER: bool

Explanation:
No explanation is available for this question!

8) We can initialize a value of static variable of a class only when its object is created. No
other initialization is permitted.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

9) 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
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

10) 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.
Answer Explanation
ANSWER: protected member is inheritable and also accessible in derived class.

Explanation:
No explanation is available for this question!

11) A friend function does not have 'this' pointer associated with it.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

12) In nested try blocks, if both inner and outer catch handlers are not able to handle the
exception, then ______________ .

a. Compiler executes only executable statements of main().


b. Compiler issues compile time errors about it.
c. Program will be executed without any interrupt.
d. Program will be terminated abnormally.
Answer Explanation
ANSWER: Program will be terminated abnormally.

Explanation:
No explanation is available for this question!

13) Throwing an unhandled exception causes standard library function then _________ to
be invoked.

a. stop()
b. aborted()
c. terminate()
d. Abandon()
Answer Explanation
ANSWER: terminate()

Explanation:
No explanation is available for this question!

14) In CPP, it is mandatory and must to initialize const variables.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

15) When a class is defined inside any function or block, it is called ___________ .

a. Nested class
b. Block class
c. Local class
d. It is not possible
Answer Explanation
ANSWER: Local class

Explanation:
No explanation is available for this question!

16) Which of the followings are false statements about Local class?

1. A local class type name can only be used in the enclosing function
2. All the methods of Local classes must be defined inside the class only
3. A Local class can contain static data members.
4. A Local class may contain static functions.
5. Non-static variables of the enclosing function are not accessible inside local classes.
6. Local classes cannot access global types, variables and functions.

a. Only 1,3
b. Only 3, 6
c. Only 2 , 4 , 6
d. None of these
Answer Explanation
ANSWER: Only 3, 6

Explanation:
No explanation is available for this question!

17) Due to ios::trunc mode, the file is truncated to zero length.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

18) A const object of a class can call non-const member function of the class.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

19) If an argument to a function is declared as const, then _______ .

a. function can modify the argument.


b. Function can’t modify the argument.
c. const argument to a function is not possible.
d. None of these
Answer Explanation
ANSWER: Function can’t modify the argument.

Explanation:
No explanation is available for this question!

20) Return type of uncaught_exception() is ________________ .

a. int
b. bool
c. char *
d. double
Answer Explanation
ANSWER: bool

Explanation:
No explanation is available for this question!

21) Can we write throw clause inside catch handler?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

22) Default values for a function are specified when ____ .

a. function is defined
b. function is declared
c. Both a and b
d. None of these
Answer Explanation
ANSWER: function is declared

Explanation:
No explanation is available for this question!

23) Can member functions of one class be friend functions of another class?

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

24) Predict the output:

float x= 3.1496;
cout << setpricision(2) << x;

a. 3.14
b. 3.15
c. 3.00
d. None of these
Answer Explanation
ANSWER: None of these

Explanation:
No explanation is available for this question!

25) 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 Explanation
ANSWER: Left hand operand must be object

1) Can constructors be overloaded?

a. Yes
b. No

Answer Explanation
ANSWER: Yes
Explanation:
No explanation is available for this question!

2) Assume class TEST. Which of the following statements is/are responsible to invoke
copy constructor?

a. TEST T2(T1)
b. TEST T4 = T1
c. T2 = T1
d. both a and b
e. All of these
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

3) When overloading unary operators using Friend function,it requires_____ argument/s.

a. Zero
b. One
c. Two
d. None of these.
Answer Explanation
ANSWER: One

Explanation:
No explanation is available for this question!

4) In CPP program, Can we declare and define a user defined function inside a struct as
we do in a class ?

a. Yes
b. No
c. Can’t say

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

5) ____________ refers to the act of representing only essential features without including
the background details.
a. Data Hiding
b. Data Encapsulation
c. Data Abstraction
d. All of these
Answer Explanation
ANSWER: Data Abstraction

Explanation:
No explanation is available for this question!

6) Runtime polymorphism is achieved only when a virtual function is accessed through a


pointer to the base class.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

7) Find the wrong statement/s about Abstract Class.

a. We can’t create its objects.


b. We can’t create pointers to an abstract class.
c. It contains at least one pure virtual function.
d. We can create references to an abstract class.
Answer Explanation
ANSWER: We can’t create pointers to an abstract class.

Explanation:
No explanation is available for this question!

8) Assigning one or more function body to the same name is called ____________ .

a. Function Overriding
b. Function Overloading
c. Both a and b
d. None of the above
Answer Explanation
ANSWER: Function Overloading

Explanation:
No explanation is available for this question!

9) Function overloading can also be achieved if two or more functions differ only in their
return types.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

10) 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().
Answer Explanation
ANSWER: Compiler will execute remaining executable statements of outer try block and
then the main().

Explanation:
No explanation is available for this question!

11) A function can be declared as friend maximum only in two classes.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

12) Which of the following statements are not true about destructor?

1. It is invoked when object goes out of the scope


2. Like constructor, it can also have parameters
3. It can be virtual
4. It can be declared in private section
5. It bears same name as that of the class and precedes Lambda sign.

a. Only 2, 3, 5
b. Only 2, 3, 4
c. Only 2, 4, 5
d. Only 3, 4, 5
Answer Explanation
ANSWER: Only 2, 4, 5

Explanation:
No explanation is available for this question!

13) 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
Answer Explanation
ANSWER: Multiple

Explanation:
No explanation is available for this question!

14) 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
Answer Explanation
ANSWER: Only 1 , 4

Explanation:
No explanation is available for this question!
15) __________________ is the OOP feature and mechanism that binds together code and
the data it manipulates, and keep both safe from outside world.

a. Data Binding
b. Data Encapsulation
c. Data Storing
d. Data Abstraction
Answer Explanation
ANSWER: Data Encapsulation

Explanation:
No explanation is available for this question!

16) Which of the followings is/are not keyword/s in CPP?

1. asm
2. boolean
3. mutable
4. export
5. constant_cast

a. Only 5
b. Only 1 and 4
c. Only 1,2 and 5
d. Only 2 and 5
Answer Explanation
ANSWER: Only 2 and 5

Explanation:
No explanation is available for this question!

17) We can create objects of the abstract class.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

18) Which of the followings are true about Virtual functions?


a. They must be non-static member function of the class
b. They cannot be friends
c. Constructor Functions cannot be virtual
d. All of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!

19) If a class contains static variable, then every object of the class has its copy of static
variable.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

20) Which of the following are member dereferencing operators in CPP?

1. *
2. ::
3. ->*
4. ::*
5. ->

a. Only 1, 3, 4
b. Only 1 and 5
c. Only 3 and 4
d. Only 3,4,5
Answer Explanation
ANSWER: Only 1, 3, 4

Explanation:
No explanation is available for this question!

21) In Multipath inheritance, in order to remove duplicate set of records in child class, we
___________ .

a. Write Virtual function in parent classes


b. Write virtual functions is base class
c. Make base class as virtual base class
d. All of these
Answer Explanation
ANSWER: Make base class as virtual base class

Explanation:
No explanation is available for this question!

22) If base class has constructor with arguments, then it is ________________ for the
derived class to have constructor and pass the arguments to base class constructor.

a. Optional
b. Mandatory
c. Compiler dependent
d. Error
Answer Explanation
ANSWER: Mandatory

Explanation:
No explanation is available for this question!

23) Using friend operator function, following perfect set of operators may not be
overloaded.

a. = , ( ) , [ ] , ->
b. <<, = = , [ ] , >>
c. ?, = , ( ) , ++
d. None of these
Answer Explanation
ANSWER: = , ( ) , [ ] , ->

Explanation:
No explanation is available for this question!

24) An operator function is created using _____________ keyword.

a. iterator
b. allocator
c. constructor
d. operator
Answer Explanation
ANSWER: operator

Explanation:
No explanation is available for this question!

25) Classes in CPP are________ .

a. derived data types


b. User defined data types
c. built-in data types
d. All of these
Answer Explanation
ANSWER: User defined data types

1) Can we define our exceptions in CPP?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

2) 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
Answer Explanation
ANSWER: Try

Explanation:
No explanation is available for this question!

3) Object based language differs from object oriented language as it does not support
features _____ .

1. Encapsulation
2. Inheritance
3. Dynamic Binding
4. Abstraction
5. Polymorphism

a. only 3 ,4
b. only 1,3,5
c. 2,4,5
d. Only 2,3
Answer Explanation
ANSWER: Only 2,3

Explanation:
No explanation is available for this question!

4) When a virtual function is redefined by the derived class, it is called___________.

a. Overloading
b. Overriding
c. Rewriting
d. All of these
Answer Explanation
ANSWER: Overriding

Explanation:
No explanation is available for this question!

5) In any ways, Non-member function cannot have access to the private data of the class.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

6) In CPP, dynamic memory allocation is done using ______________ operator.

a. calloc()
b. malloc()
c. allocate
d. New
Answer Explanation
ANSWER: New
Explanation:
No explanation is available for this question!

7) Can we allocate memory for the objects dynamically in CPP?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

8) If the derived class is struct, then default visibility mode is _______ .

a. public
b. protected
c. private
d. struct can’t inherit class
Answer Explanation
ANSWER: public

Explanation:
No explanation is available for this question!

9) Which of the following manipulator is used for the representing octal equivalent of a
given decimal number?

a. oct
b. setbase(8)
c. tobase(8)
d. both a and b
e. all a, b, c
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

10) Which of the following is not a casting operator in CPP?

a. explicit_cast
b. static_cast
c. dynamic_cast
d. reinterpret_cast
Answer Explanation
ANSWER: explicit_cast

Explanation:
No explanation is available for this question!

11) ___________ header file is used for manipulators.

a. < iomanipulator.h>
b. < stdiomanip.h>
c. < stdmanip.h>
d. < iomanip.h>
Answer Explanation
ANSWER: < iomanip.h>

Explanation:
No explanation is available for this question!

12) While redefining a virtual function in the derived class, if its prototype is changed then
___________________ .

a. It will be overloaded by the compiler


b. Its virtual nature will be lost
c. both a and b
d. Compiler will generate “Prototype mismatch error”
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

13) const member function does not allow to modify/alter value of any data member of the
class.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!
14) In a program, If there exists a function template with two parameters and normal
function say void add(int , int), so add(3,4) will _____________________ .

a. Invoke function template body as it is generic one


b. Invokes normal function as it exactly matches with its prototype
c. Not be called and Compiler issues warning
d. Not be called and Compiler issues ambiguity in calling add()
Answer Explanation
ANSWER: Invokes normal function as it exactly matches with its prototype

Explanation:
No explanation is available for this question!

15) Can struct be used as Base class for inheritance ?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

16) 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
Answer Explanation
ANSWER: constructor of base class will be executed first followed by derived class

Explanation:
No explanation is available for this question!

17) Which of the following is not a file opening mode ____ .

a. ios::ate
b. ios::nocreate
c. ios::noreplace
d. ios::truncate
Answer Explanation
ANSWER: ios::truncate

Explanation:
No explanation is available for this question!

18) Attempting to throw an exception that is not supported by a function call results in
calling _____________ library function.

a. indeterminate()
b. unutilized()
c. unexpected()
d. unpredicted()
Answer Explanation
ANSWER: unexpected()

Explanation:
No explanation is available for this question!

19) How can we restrict a function to throw certain exceptions?

a. Defining multiple try and catch block inside a function


b. Defining generic function within try block
c. Defining function with throw clause
d. It is not possible in CPP to restrict a function
Answer Explanation
ANSWER: Defining function with throw clause

Explanation:
No explanation is available for this question!

20) Is it possible to define a constructor with default arguments?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

21) The purpose of explicit keyword is to tell the compiler that a certain constructor may
not be used to implicitly cast an expression to its class type.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

22) 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 Explanation
ANSWER: to resolve scope of global variables as well as functions of the classes

Explanation:
No explanation is available for this question!

23) 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
Answer Explanation
ANSWER: Only 2 , 3

Explanation:
No explanation is available for this question!

24) A try block can be nested under another try block.

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

25) In nested try blocks, there is no need to specify catch handler for inner try block.
Outer catch handler is sufficient for the program.

a. True
b. False

Answer Explanation

ANSWER: False

1) We can prevent a function from throwing any exceptions.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

2) Functions called from within a try block may also throw exception.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

3) The explicit keyword is an optional decoration for the constructors that takes
exactly_____argument.

a. No argument
b. Two
c. Three
d. One
Answer Explanation
ANSWER: One

Explanation:
No explanation is available for this question!

4) A class can contain objects of other classes and this phenomenon is called_________ .

a. Relationship
b. Object Association
c. Containership
d. None of these
Answer Explanation
ANSWER: Containership

Explanation:
No explanation is available for this question!

5) Can we alter/modify the values of data members of a class inside const member
function?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

6) If a class contains pure virtual function, then it is termed as____________________ .

a. Virtual class
b. Sealed class
c. Pure Local class
d. Abstract Class
Answer Explanation
ANSWER: Abstract Class

Explanation:
No explanation is available for this question!

7) 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 these
Answer Explanation
ANSWER: Compiler will check for appropriate catch handler of outer try block

Explanation:
No explanation is available for this question!

8) Generic catch handler is represented by ______________ .

a. catch(..,)
b. catch(---)
c. catch(…)
d. catch( void x)
Answer Explanation
ANSWER: catch(…)

Explanation:
No explanation is available for this question!

9) Which one is suitable syntax for function template?

a. template< class T> return_type Function_Name(parameters)


b. template< typename T> return_type Function_Name(parameters)
c. both a and b
d. None of these
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

10) It is not possible to combine two or more file opening mode in open () method.

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

11) Private members of the class are not inheritable.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

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

a. Zero
b. One
c. Two
d. Three
Answer Explanation
ANSWER: One

Explanation:
No explanation is available for this question!

13) If abstract class is inherited by derived class, then_______________ .

a. Derived class should provide definition for all the pure virtual functions
b. Derived class also become abstract if fails to implement pure virtual functions
c. Objects of derived class can’t be created if it fails to implement pure virtual functions
d. All of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!
14) By default, all the files are opened in ___________mode .

a. Binary
b. Text
c. Can’t say

Answer Explanation
ANSWER: Text

Explanation:
No explanation is available for this question!

15) Generic catch handler must be placed at the end of all the catch handlers.

a. True
b. False

Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

16) An exception can be of only built-In type.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

17) The CPP compiler supports automatic type conversions for the user defined
datatypes.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

18) Can a class be declared/defined inside another class ?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

19) Can we pass parameters to base class constructor though derived class or derived
class constructor?

a. Yes
b. No

Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

20) _________________are used for generic programming.

a. Inheritance
b. Virtual Functions
c. Templates
d. None of these
Answer Explanation
ANSWER: Templates

Explanation:
No explanation is available for this question!

21) Irrespective of exception occurrence, catch handler will always get executed.

a. True
b. False

Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

22) In CPP, cin and cout are the predefined stream __________ .

a. Operator
b. Functions
c. Objects
d. Data types
Answer Explanation
ANSWER: Objects

Explanation:
No explanation is available for this question!

23) Object oriented programming employs_________ programming approach.

a. top-down
b. procedural
c. bottom-up
d. all of these.
Answer Explanation
ANSWER: bottom-up

Explanation:
No explanation is available for this question!

24) Constant variables can be created in CPP by using ________ .

a. enum
b. const
c. #define
d. All of these
e. None of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!
25) A virtual function that has no definition within the base class is called____________.

a. Pure virtual function


b. Pure static function
c. Pure Const function
d. Friend function
Answer Explanation
ANSWER: Pure virtual function

Here, you can read C++ basic concepts multiple choice questions and answers with explanation.

 1) Constant variables can be created in CPP by using ________ .


- Published on 19 Oct 15

a. enum
b. const
c. #define
d. All of these
e. None of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!

2) Object oriented programming employs_________ programming approach.


- Published on 19 Oct 15

a. top-down
b. procedural
c. bottom-up
d. all of these.
Answer Explanation
ANSWER: bottom-up

Explanation:
No explanation is available for this question!

3) In CPP, cin and cout are the predefined stream __________ .


- Published on 19 Oct 15

a. Operator
b. Functions
c. Objects
d. Data types
Answer Explanation
ANSWER: Objects

Explanation:
No explanation is available for this question!

4) _________________are used for generic programming.


- Published on 19 Oct 15

a. Inheritance
b. Virtual Functions
c. Templates
d. None of these
Answer Explanation
ANSWER: Templates

Explanation:
No explanation is available for this question!

5) Can a class be declared/defined inside another class ?


- Published on 19 Oct 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

6) The CPP compiler supports automatic type conversions for the user defined datatypes.
- Published on 19 Oct 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

7) Which one is suitable syntax for function template?


- Published on 19 Oct 15

a. template< class T> return_type Function_Name(parameters)


b. template< typename T> return_type Function_Name(parameters)
c. both a and b
d. None of these
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

8) A class can contain objects of other classes and this phenomenon is called_________ .
- Published on 19 Oct 15

a. Relationship
b. Object Association
c. Containership
d. None of these
Answer Explanation
ANSWER: Containership

Explanation:
No explanation is available for this question!

9) While redefining a virtual function in the derived class, if its prototype is changed then
___________________ .
- Published on 19 Jul 15

a. It will be overloaded by the compiler


b. Its virtual nature will be lost
c. both a and b
d. Compiler will generate “Prototype mismatch error”
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

10) Object based language differs from object oriented language as it does not support
features _____ .
1. Encapsulation
2. Inheritance
3. Dynamic Binding
4. Abstraction
5. Polymorphism
- Published on 19 Jul 15

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

ANSWER: Only 2,3

Here, you can read C++ basic concepts multiple choice questions and answers with explanation.

 11) Classes in CPP are________ .


- Published on 17 Jul 15

a. derived data types


b. User defined data types
c. built-in data types
d. All of these
Answer Explanation
ANSWER: User defined data types

Explanation:
No explanation is available for this question!

12) If a class contains static variable, then every object of the class has its copy of static
variable.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!
13) Which of the followings is/are not keyword/s in CPP?

1. asm
2. boolean
3. mutable
4. export
5. constant_cast
- Published on 17 Jul 15

a. Only 5
b. Only 1 and 4
c. Only 1,2 and 5
d. Only 2 and 5
Answer Explanation
ANSWER: Only 2 and 5

Explanation:
No explanation is available for this question!

14) __________________ is the OOP feature and mechanism that binds together code and
the data it manipulates, and keep both safe from outside world.
- Published on 17 Jul 15

a. Data Binding
b. Data Encapsulation
c. Data Storing
d. Data Abstraction
Answer Explanation
ANSWER: Data Encapsulation

Explanation:
No explanation is available for this question!

15) ____________ refers to the act of representing only essential features without
including the background details.
- Published on 17 Jul 15

a. Data Hiding
b. Data Encapsulation
c. Data Abstraction
d. All of these
Answer Explanation
ANSWER: Data Abstraction

Explanation:
No explanation is available for this question!

16) In CPP program, Can we declare and define a user defined function inside a struct as
we do in a class ?
- Published on 17 Jul 15

a. Yes
b. No
c. Can’t say
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

17) Which of the followings are false statements about Local class?

1. A local class type name can only be used in the enclosing function
2. All the methods of Local classes must be defined inside the class only
3. A Local class can contain static data members.
4. A Local class may contain static functions.
5. Non-static variables of the enclosing function are not accessible inside local classes.
6. Local classes cannot access global types, variables and functions.

- Published on 17 Jul 15

a. Only 1,3
b. Only 3, 6
c. Only 2 , 4 , 6
d. None of these
Answer Explanation
ANSWER: Only 3, 6

Explanation:
No explanation is available for this question!

18) When a class is defined inside any function or block, it is called ___________ .
- Published on 17 Jul 15

a. Nested class
b. Block class
c. Local class
d. It is not possible
Answer Explanation
ANSWER: Local class

Explanation:
No explanation is available for this question!

19) In CPP, it is mandatory and must to initialize const variables.


- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

20) We can initialize a value of static variable of a class only when its object is created. No
other initialization is permitted.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation

ANSWER: False

Here, you can read C++ basic concepts multiple choice questions and answers with explanation.

 21) Logical expressions produce ____________ type results.


- Published on 17 Jul 15

a. explicit
b. garbage
c. bool
d. static
Answer Explanation
ANSWER: bool

Explanation:
No explanation is available for this question!

22) Only functions of the class can access the data of the class and they(functions)
provides the interface between data, objects and the program. This kind isolation of the
data from direct access by the program is called _______________ .

- Published on 17 Jul 15

a. Data Abstraction
b. Data Hiding
c. Data Binding
d. Data Encapsulation
Answer Explanation
ANSWER: Data Hiding

Explanation:
No explanation is available for this question!

23) Public data members and member functions of the class are accessible ONLY to the
member functions of that class.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

24) Predict the output:

int x = 786;
cout << setfill(‘*’) << setw(6) << x;

- Published on 17 Jul 15

a. 786***
b. **786
c. ***786
d. ******
Answer Explanation
ANSWER: ***786

Explanation:
No explanation is available for this question!

25) Private members of the class are accessible only to the members of the same class.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

26) Static variable declared in a class are also called_________ .


- Published on 17 Jul 15

a. instance variable
b. named constant
c. global variable
d. class variable
Answer Explanation
ANSWER: class variable

Explanation:
No explanation is available for this question!

27) Static variable must be declared in public section of the class.


- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

28) Which of the following are true about static member function?

1. They can access non-static data members.


2. They can call only other static member functions.
3. They can access global functions and data.
4. They can have this pointer.
5. They cannot be declared as const or volatile.
- Published on 17 Jul 15

a. Only 2
b. Only 2,5
c. Only 2,3,4,5
d. Only 2 , 3 , 5
e. All of these
Answer Explanation
ANSWER: Only 2 , 3 , 5

Explanation:
No explanation is available for this question!

29) C structure differs from CPP class in regards that by default all the members of the
structure are __________ in nature.
- Published on 17 Jul 15

a. private
b. protected
c. public
d. None of these
Answer Explanation
ANSWER: public

Explanation:
No explanation is available for this question!

30) Members of the class can be declared with auto, extern or register storage classes.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation

ANSWER: False

Here, you can read C++ basic concepts multiple choice questions and answers with explanation.

 31) Which of the followings is/are not a manipulator/s ?

1. flush
2. base
3. ends
4. oct
5. bin
6. skipws
- Published on 17 Jul 15

a. Only 1, 6
b. Only 1,4,6
c. Only 1,3,6
d. Only 2,5
Answer Explanation
ANSWER: Only 2,5

Explanation:
No explanation is available for this question!

32) Static variable in a class is initialized when _____ .


- Published on 17 Jul 15

a. every object of the class is created.


b. last object of the class is created.
c. first object of the class is created.
d. No need to initialize static variable.
Answer Explanation
ANSWER: first object of the class is created.

Explanation:
No explanation is available for this question!

33) In CPP, the size of the character array should be one larger than the number of
characters in the string.

- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

34) If a program uses Inline Function, then the function is expanded inline at
___________.
- Published on 17 Jul 15

a. Compile time
b. Run time
c. Both a and b
d. None of these
Answer Explanation
ANSWER: Run time

Explanation:
No explanation is available for this question!

35) Which of the following is CPP style type-casting?


- Published on 17 Jul 15

a. per = total/(float)m
b. per = total/float(m)
c. per = (float)total/m
d. None of these
Answer Explanation
ANSWER: per = total/float(m)

Explanation:
No explanation is available for this question!

36) class TEST


{
private:
int roll_no;
public:
int age;
char name[20];
private:
int grade;
protected:
char gender[20];
private:

private:
int m1, m2, m3;
};

In general view, is this class definition valid?

- Published on 17 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

37) By default, members of the class are ____________ in nature.


- Published on 17 Jul 15

a. protected
b. private
c. public
d. static
Answer Explanation
ANSWER: private

Explanation:
No explanation is available for this question!

38) ________ are used to format the data display in CPP.


- Published on 17 Jul 15

a. Iterators
b. Punctuators
c. Manipulators
d. Allocators
Answer Explanation
ANSWER: Manipulators

Explanation:
No explanation is available for this question!

39) Default value of static variable is_____ .


- Published on 17 Jul 15

a. 0
b. 1
c. Garbage value
d. Compiler dependent
Answer Explanation

ANSWER: 0
Here, you can read Constructor and Destructor multiple choice questions and answers with
explanation.

 1) The explicit keyword is an optional decoration for the constructors that takes
exactly_____argument.
- Published on 19 Oct 15

a. No argument
b. Two
c. Three
d. One
Answer Explanation
ANSWER: One

Explanation:
No explanation is available for this question!

2) The purpose of explicit keyword is to tell the compiler that a certain constructor may
not be used to implicitly cast an expression to its class type.
- Published on 19 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

3) Is it possible to define a constructor with default arguments?


- Published on 19 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

4) Which of the following statements are not true about destructor?

1. It is invoked when object goes out of the scope


2. Like constructor, it can also have parameters
3. It can be virtual
4. It can be declared in private section
5. It bears same name as that of the class and precedes Lambda sign.
- Published on 17 Jul 15

a. Only 2, 3, 5
b. Only 2, 3, 4
c. Only 2, 4, 5
d. Only 3, 4, 5
Answer Explanation
ANSWER: Only 2, 4, 5

Explanation:
No explanation is available for this question!

5) Assume class TEST. Which of the following statements is/are responsible to invoke
copy constructor?
- Published on 17 Jul 15

a. TEST T2(T1)
b. TEST T4 = T1
c. T2 = T1
d. both a and b
e. All of these
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

6) Can constructors be overloaded?


- Published on 17 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

7) A Constructor that does not have any parameters is called____________ Constructor.


- Published on 17 Jul 15
a. Custom
b. Dynamic
c. Static
d. Default
Answer Explanation
ANSWER: Default

Explanation:
No explanation is available for this question!

8) 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.
- Published on 17 Jul 15

a. Only 1,2,4
b. 1,2,4,5
c. 1,3,5
d. 1,4,5
Answer Explanation
ANSWER: 1,4,5

Explanation:
No explanation is available for this question!

9) Is it mandatory to invoke/call a constructor for creating an object?


- Published on 17 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

10) If default constructor is not defined, then how the objects of the class will be created?
- Published on 17 Jul 15

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
Answer Explanation
ANSWER: Compiler provides its default constructor to build the object.

Here, you can read Inheritance multiple choice questions and answers with explanation.

 1) Can we pass parameters to base class constructor though derived class or derived
class constructor?
- Published on 19 Oct 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

2) Private members of the class are not inheritable.


- Published on 19 Oct 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

3) In case of inheritance where both base and derived class are having constructors, when
an object of derived class is created then___________ .
- Published on 19 Jul 15

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
Answer Explanation
ANSWER: constructor of base class will be executed first followed by derived class

Explanation:
No explanation is available for this question!

4) Can struct be used as Base class for inheritance ?


- Published on 19 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

5) If the derived class is struct, then default visibility mode is _______ .


- Published on 19 Jul 15

a. public
b. protected
c. private
d. struct can’t inherit class
Answer Explanation
ANSWER: public

Explanation:
No explanation is available for this question!

6) If base class has constructor with arguments, then it is ________________ for the
derived class to have constructor and pass the arguments to base class constructor.
- Published on 17 Jul 15

a. Optional
b. Mandatory
c. Compiler dependent
d. Error
Answer Explanation
ANSWER: Mandatory

Explanation:
No explanation is available for this question!

7) In Multipath inheritance, in order to remove duplicate set of records in child class, we


___________ .
- Published on 17 Jul 15

a. Write Virtual function in parent classes


b. Write virtual functions is base class
c. Make base class as virtual base class
d. All of these
Answer Explanation
ANSWER: Make base class as virtual base class

Explanation:
No explanation is available for this question!

8) 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
- Published on 17 Jul 15

a. Only 2 ,4
b. Only 1 , 3
c. Only 1 , 4
d. Only 2, 3
Answer Explanation
ANSWER: Only 1 , 4

Explanation:
No explanation is available for this question!

9) When a child class inherits traits from more than one parent class, this type of
inheritance is called _______________ inheritance.
- Published on 17 Jul 15

a. Hierarchical
b. Hybrid
c. Multilevel
d. Multiple
Answer Explanation
ANSWER: Multiple

Explanation:
No explanation is available for this question!

10) What is the difference between protected and private access specifiers in inheritance?
- Published on 17 Jul 15
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.
Answer Explanation
ANSWER: protected member is inheritable and also accessible in derived class

Here, you can read Inheritance multiple choice questions and answers with explanation.

 11) When a base class is privately inherited by the derived class, then_____________ .
- Published on 17 Jul 15

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
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

12) The derivation of Child class from Base class is indicated by ____ symbol.
- Published on 17 Jul 15

a. ::
b. :
c. ;
d. |
Answer Explanation
ANSWER: :

Explanation:
No explanation is available for this question!

13) During a class inheritance in CPP, if the visibility mode or mode of derivation is not
provided, then by default visibility mode is ___________.
- Published on 17 Jul 15

a. public
b. protected
c. private
d. Friend
Answer Explanation
ANSWER: private

Explanation:
No explanation is available for this question!

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

- Published on 17 Jul 15

a. Only 1, 5
b. Only 1, 6
c. Only 2, 6
d. Only 2, 4
Answer Explanation
ANSWER: Only 2, 4

Explanation:
No explanation is available for this question!

15) class X, class Y and class Z are derived from class BASE. This is ______ inheritance.
- Published on 17 Jul 15

a. Multiple
b. Multilevel
c. Hierarchical
d. Single
Answer Explanation
ANSWER: Hierarchical

Explanation:
No explanation is available for this question!

16) Reusability of the code can be achieved in CPP through ______ .


- Published on 17 Jul 15

a. Polymorphism
b. Encapsulation
c. Inheritance
d. Both a and c
Answer Explanation
ANSWER: Inheritance

Here, you can read File Handling multiple choice questions and answers with explanation.

 1) By default, all the files are opened in ___________mode .


- Published on 19 Oct 15

a. Binary
b. Text
c. Can’t say
Answer Explanation
ANSWER: Text

Explanation:
No explanation is available for this question!

2) It is not possible to combine two or more file opening mode in open () method.
- Published on 19 Oct 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

3) Which of the following is not a file opening mode ____ .


- Published on 19 Jul 15

a. ios::ate
b. ios::nocreate
c. ios::noreplace
d. ios::truncate
Answer Explanation
ANSWER: ios::truncate

Explanation:
No explanation is available for this question!

4) Due to ios::trunc mode, the file is truncated to zero length.


- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

5) If we have object from ofstream class, then default mode of opening the file is _____ .
- Published on 17 Jul 15

a. ios::in
b. ios::out
c. ios::in|ios::trunc
d. ios::out|ios::trunk
Answer Explanation
ANSWER: ios::out|ios::trunk

Explanation:
No explanation is available for this question!

6) __________ is return type of is_open() function.


- Published on 17 Jul 15

a. int
b. bool
c. float
d. char *
Answer Explanation
ANSWER: bool

Explanation:
No explanation is available for this question!

7) If we have object from fstream class, then what is the default mode of opening the file?
- Published on 17 Jul 15

a. ios::in|ios::out
b. ios::in|ios::out|ios::trunc
c. ios::in|ios::trunc
d. Default mode depends on compiler
Answer Explanation
ANSWER: Default mode depends on compiler

Explanation:
No explanation is available for this question!

8) To create an output stream, we must declare the stream to be of class ___________ .


- Published on 17 Jul 15

a. ofstream
b. ifstream
c. iostream
d. None of these
Answer Explanation
ANSWER: ofstream

Explanation:
No explanation is available for this question!

9) Streams that will be performing both input and output operations must be declared as
class _________ .
- Published on 17 Jul 15

a. iostream
b. fstream
c. stdstream
d. Stdiostream
Answer Explanation
ANSWER: fstream

Explanation:
No explanation is available for this question!

10) To perform File I/O operations, we must use _____________ header file.
- Published on 17 Jul 15

a. < ifstream>
b. < ofstream>
c. < fstream>
d. Any of these
Answer Explanation
ANSWER: < fstream>
11) Which of the following is not used to seek a file pointer?
- Published on 17 Jul 15

a. ios::cur
b. ios::set
c. ios::end
d. ios::beg
Answer Explanation

ANSWER: ios::set

Here, you can read Memory Management multiple choice questions and answers with
explanation.

 1) Can we allocate memory for the objects dynamically in CPP?


- Published on 19 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

2) In CPP, dynamic memory allocation is done using ______________ operator.


- Published on 19 Jul 15

a. calloc()
b. malloc()
c. allocate
d. New
Answer Explanation
ANSWER: New

Explanation:
No explanation is available for this question!

3) Which of the following is not a false statement about new operator?


- Published on 17 Jul 15

a. It can’t be overloaded.
b. It returns garbage value when memory allocation fails.
c. It automatically computes the size of the data object.
d. All of these
Answer Explanation
ANSWER: It automatically computes the size of the data object.

Explanation:
No explanation is available for this question!

4) Which of the following operator is used to release the dynamically allocated memory in
CPP?
- Published on 17 Jul 15

a. remove
b. free
c. delete
d. both b and c
Answer Explanation
ANSWER: delete

Explanation:
No explanation is available for this question!

5) Which of the following is/are valid ways to allocate memory for an integer by dynamic
memory allocation in CPP?
- Published on 17 Jul 15

a. int *p = new int(100);


b. int *p; p = new int; *p = 100;
c. int *p = NULL; p = new int; *p=100;
d. Only 1,2
e. All of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!

6) During dynamic memory allocation in CPP, new operator returns _________ value if
memory allocation is unsuccessful.

- Published on 17 Jul 15

a. False
b. NULL
c. Zero
d. None of these
Answer Explanation

ANSWER: NULL

Operator Overloading - C++ (MCQ)


questions and answers
 Home >> Category >> C++ (MCQ) questions and answers

Here, you can read Operator Overloading multiple choice questions and answers with
explanation.

 1) While overloading binary operators using member function, it requires ___


argument/s.
- Published on 19 Oct 15

a. Zero
b. One
c. Two
d. Three
Answer Explanation
ANSWER: One

Explanation:
No explanation is available for this question!

2) In case of operator overloading, operator function must be ______ .

1. Static member functions


2. Non- static member functions
3. Friend Functions
- Published on 19 Jul 15

a. Only 2
b. Only 1, 3
c. Only 2 , 3
d. All 1 , 2, 3
Answer Explanation
ANSWER: Only 2 , 3

Explanation:
No explanation is available for this question!

3) Scope resolution operator is used______ .


- Published on 19 Jul 15

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 Explanation
ANSWER: to resolve scope of global variables as well as functions of the classes

Explanation:
No explanation is available for this question!

4) ___________ header file is used for manipulators.


- Published on 19 Jul 15

a. < iomanipulator.h>
b. < stdiomanip.h>
c. < stdmanip.h>
d. < iomanip.h>
Answer Explanation
ANSWER: < iomanip.h>

Explanation:
No explanation is available for this question!

5) Which of the following is not a casting operator in CPP?


- Published on 19 Jul 15

a. explicit_cast
b. static_cast
c. dynamic_cast
d. reinterpret_cast
Answer Explanation
ANSWER: explicit_cast

Explanation:
No explanation is available for this question!

6) Which of the following manipulator is used for the representing octal equivalent of a
given decimal number?
- Published on 19 Jul 15

a. oct
b. setbase(8)
c. tobase(8)
d. both a and b
e. all a, b, c
Answer Explanation
ANSWER: both a and b

Explanation:
No explanation is available for this question!

7) An operator function is created using _____________ keyword.


- Published on 17 Jul 15

a. iterator
b. allocator
c. constructor
d. operator
Answer Explanation
ANSWER: operator

Explanation:
No explanation is available for this question!

8) Using friend operator function, following perfect set of operators may not be
overloaded.
- Published on 17 Jul 15

a. = , ( ) , [ ] , ->
b. <<, = = , [ ] , >>
c. ?, = , ( ) , ++
d. None of these
Answer Explanation
ANSWER: = , ( ) , [ ] , ->

Explanation:
No explanation is available for this question!

9) When overloading unary operators using Friend function,it requires_____ argument/s.


- Published on 17 Jul 15

a. Zero
b. One
c. Two
d. None of these.
Answer Explanation
ANSWER: One

Explanation:
No explanation is available for this question!

10) In case of binary operator overloading with member function, which of following
statement should be taken into consideration?
- Published on 17 Jul 15

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 Explanation
ANSWER: Left hand operand must be object

11) Which of the following is the perfect set of operators that can’t be overloaded in CPP
?
- Published on 17 Jul 15

a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()
c. :: , . , .* , ?:
d. :: , ->, * , new, delete
Answer Explanation
ANSWER: :: , . , .* , ?:

Here, you can read Polymorphism and Abstract Classes multiple choice questions and answers
with explanation.

 1) A virtual function that has no definition within the base class is called____________.
- Published on 19 Oct 15

a. Pure virtual function


b. Pure static function
c. Pure Const function
d. Friend function
Answer Explanation
ANSWER: Pure virtual function

Explanation:
No explanation is available for this question!

2) If abstract class is inherited by derived class, then_______________ .


- Published on 19 Oct 15

a. Derived class should provide definition for all the pure virtual functions
b. Derived class also become abstract if fails to implement pure virtual functions
c. Objects of derived class can’t be created if it fails to implement pure virtual functions
d. All of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!

3) If a class contains pure virtual function, then it is termed as____________________ .


- Published on 19 Oct 15

a. Virtual class
b. Sealed class
c. Pure Local class
d. Abstract Class
Answer Explanation
ANSWER: Abstract Class

Explanation:
No explanation is available for this question!

4) When a virtual function is redefined by the derived class, it is called___________.


- Published on 19 Jul 15

a. Overloading
b. Overriding
c. Rewriting
d. All of these
Answer Explanation
ANSWER: Overriding
Explanation:
No explanation is available for this question!

5) Which of the followings are true about Virtual functions?


- Published on 17 Jul 15

a. They must be non-static member function of the class


b. They cannot be friends
c. Constructor Functions cannot be virtual
d. All of these
Answer Explanation
ANSWER: All of these

Explanation:
No explanation is available for this question!

6) We can create objects of the abstract class.


- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

7) Find the wrong statement/s about Abstract Class.


- Published on 17 Jul 15

a. We can’t create its objects.


b. We can’t create pointers to an abstract class.
c. It contains at least one pure virtual function.
d. We can create references to an abstract class.
Answer Explanation
ANSWER: We can’t create pointers to an abstract class.

Explanation:
No explanation is available for this question!

8) Runtime polymorphism is achieved only when a virtual function is accessed through a


pointer to the base class.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

9) Syntax for Pure Virtual Function is ______________ .


- Published on 17 Jul 15

a. virtual void show()==0


b. void virtual show()==0
c. virtual void show()=0
d. void virtual show()=0
Answer Explanation
ANSWER: virtual void show()=0

Explanation:
No explanation is available for this question!

10) _______________ is a member function that is declared within a base class and
redefined by derived class.
- Published on 17 Jul 15

a. virtual function
b. static function
c. friend function
d. const member function
Answer Explanation
ANSWER: virtual function

Here, you can read Polymorphism and Abstract Classes multiple choice questions and answers
with explanation.

 11) Run time polymorphism can be achieved with______ .


- Published on 17 Jul 15

a. Virtual Base class


b. Container class
c. Virtual function
d. Both a and c
Answer Explanation
ANSWER: Virtual function

Explanation:
No explanation is available for this question!

12) We can create objects of the abstract class.


- Published on 17 Jul 15

a. True
b. False
Answer Explanation

ANSWER: False
Here, you can read Functions multiple choice questions and answers with explanation.

 1) Can we alter/modify the values of data members of a class inside const member
function?
- Published on 19 Oct 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

2) In a program, If there exists a function template with two parameters and normal
function say void add(int , int), so add(3,4) will _____________________ .
- Published on 19 Jul 15

a. Invoke function template body as it is generic one


b. Invokes normal function as it exactly matches with its prototype
c. Not be called and Compiler issues warning
d. Not be called and Compiler issues ambiguity in calling add()
Answer Explanation
ANSWER: Invokes normal function as it exactly matches with its prototype

Explanation:
No explanation is available for this question!

3) const member function does not allow to modify/alter value of any data member of the
class.
- Published on 19 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

4) In any ways, Non-member function cannot have access to the private data of the class.
- Published on 19 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

5) A function can be declared as friend maximum only in two classes.


- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

6) Function overloading can also be achieved if two or more functions differ only in their
return types.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

7) Assigning one or more function body to the same name is called ____________ .
- Published on 17 Jul 15

a. Function Overriding
b. Function Overloading
c. Both a and b
d. None of the above
Answer Explanation
ANSWER: Function Overloading

Explanation:
No explanation is available for this question!

8) Predict the output:

float x= 3.1496;
cout << setpricision(2) << x;

- Published on 17 Jul 15

a. 3.14
b. 3.15
c. 3.00
d. None of these
Answer Explanation
ANSWER: None of these

Explanation:
No explanation is available for this question!

9) Can member functions of one class be friend functions of another class?


- Published on 17 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

10) Default values for a function are specified when ____ .


- Published on 17 Jul 15

a. function is defined
b. function is declared
c. Both a and b
d. None of these
Answer Explanation
ANSWER: function is declared

Here, you can read Functions multiple choice questions and answers with explanation.

 11) If an argument to a function is declared as const, then _______ .


- Published on 17 Jul 15

a. function can modify the argument.


b. Function can’t modify the argument.
c. const argument to a function is not possible.
d. None of these
Answer Explanation
ANSWER: Function can’t modify the argument.

Explanation:
No explanation is available for this question!

12) A const object of a class can call non-const member function of the class.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

13) A friend function does not have 'this' pointer associated with it.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!
14) Default values for a function are need to be specified from left to right only.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: False

Explanation:
No explanation is available for this question!

15) Default return type of functions in CPP is ____ .


- Published on 17 Jul 15

a. void
b. long
c. char
d. Int
Answer Explanation
ANSWER: Int

Explanation:
No explanation is available for this question!

16) Which of the followings is/are not false about friend function ?

1. It can be called / invoked with class object.


2. It has objects as arguments.
3. It can have built-in types as arguments.
4. It must declared only in public part of a class.
5. It does not have this pointer as an argument.

- Published on 17 Jul 15

a. Only 2,4
b. Only 1,2,5
c. Only 2,3,5
d. All of these
Answer Explanation
ANSWER: Only 2,3,5

Explanation:
No explanation is available for this question!
17) Inline functions may not work ______ .

1. If function contain static variables.


2. If function contain global and register variables.
3. If function returning value consists looping construct(i.e. for, while).
4. If inline functions are recursive.
5. If function contains const value.
- Published on 17 Jul 15

a. Only 1,4,5
b. Only 2,3,5
c. Only 1,3,4
d. All of these
Answer Explanation
ANSWER: Only 1,3,4

Explanation:
No explanation is available for this question!

18) Can we have overloading of the function templates?


- Published on 17 Jul 15

a. Yes
b. No
Answer Explanation
ANSWER: Yes

Explanation:
No explanation is available for this question!

19) By default, if a function with minimum lines of code is declared and defined inside the
class becomes Inline function.
- Published on 17 Jul 15

a. True
b. False
Answer Explanation
ANSWER: True

Explanation:
No explanation is available for this question!

20) Which of the following best defines the syntax for template function ?
- Published on 17 Jul 15
a. Template
b. Template return_type Function_Name(Parameters)
c. Both a and b
d. None of these
Answer Explanation
ANSWER: Both a and b

1. Which of the following correctly declares an array?

 A. int array[10];
 B. int array;
 C. array{10};
 D. array array[10];

 View Answer
 Workspace
 Report
 Discuss

2. What is the index number of the last element of an array with 9 elements?

 A. 9
 B. 8
 C. 0
 D. Programmer-defined

 View Answer
 Workspace
 Report
 Discuss

3. What is a array?

 A. n 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

 View Answer
 Workspace
 Report
 Discuss
4. Which of the following accesses the seventh element stored in array?

 A. array[6];
 B. array[7];
 C. array(7);
 D. array;

 View Answer
 Workspace
 Report
 Discuss

5. 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;

 View Answer
 Workspace
 Report
 Discuss

Answer & Explanation

Answer: Option D

Explanation:

array;

Q) In C++ code , variables can be passed to a function by

A. Pass by value
B. Pass by reference
C. Pass by pointer
D. All the above

View Answer
Answer: D
In C++ programming, all pass by value, reference and pointer are used. Note that pass by reference in C
Programming language is not available. However, sometimes people use the term pass by reference
instead of pass by address or pass by pointers. Read here pass by value and pass by pointer in C
programming and difference between pass by pointer and pass by reference in C++ language.

Q) Constant function in C++ can be declared as

A. void display()
B. void display() const
C. const void display()
D. void const display()

View Answer
Answer: B

Constant function in a class is used to prevent modification of class member variables inside its
body. When we only want to read member variable and use it in function body with no
modification then we should use const function. Read detail of constant function in C++ object
oriented programming.

Q) True and false statements about inline function in given C++ code example is/are

(I)Static function of a class can be called by class name using scope resolution operator i.e. : :
(II)Static function can receive both static and non-static data members of a class
(III)Static function is not the part of an object of a class

A. I and II
B. I only
C. I and III
D. I, II and III

View Answer
Answer: C

Read in detail about static function in C++ with example and if static function can access
non static data in C++ program.
Q) Which of the following functions are provided by compiler by default if we don’t write in a C++
class?

A. Copy constructor
B. Assignment
C. Constructor
D. All the above

View Answer
Answer: D

All functions are provided by compiler if we don’t write in a class. Read more on default
functions provided by compiler in C++

Q) Which function can be called without using an object of a class in C++

A. Static function
B. Inline function
C. Friend function
D. constant function

View Answer
Answer: A

Q) True and false about inline function statements in C++


class A{
public:
void func1(){
}
void func2();
};
inline void A::func2(){

A. Func1 is inline function


B. Func2 only is inline function
C. Func1 and Func2 both are inline functions
D. None of the above is inline

View Answer
Answer: C

Q) Which function can be called without using an object of a class in C++

A. Virtual function
B. Inline function
C. Static function
D. constant function

View Answer
Answer: C

Q) Which of the following function declaration using default arguments is incorrect?

A. int foo(int x, int y =5, int z=10)


B. int foo(int x=5, int y =10, int z)
C. int foo(int x=5, int y, int z=10)
D. all are correct

View Answer
Answer: A
Explanation:Default arguments in a function in C++ program is initialized from right to left.

Q) Which function cannot be overloaded in C++ program?

A. Virtual function
B. member function
C. Static function
D. All can be overloaded

View Answer
Answer: C
Static functions cannot be overloaded in C++ programming. You can read static function in C++ and how
it differs from C.
Q) Choose the correct answer for following piece of C++ pseudo code
void func(int a, int &b)
{

int main(){
int a,b;
func(a,b);
}

A. a is pass by value and b is pass by reference


B. a is pass by reference and b is pass by value
C. a is pass by value and b is pass by address
D. a is pass by value and b is pass by pointer

View Answer
Answer: A
B parameter is not pass by address/pointer but reference. Here is the correct pseudo code for pass by
address or say pointer.

void func(int a, int *b)


{

int main(){
int a,b;
func(a,&b);
}

Read about difference between pointer and reference in C++

Q) Overloaded functions in C++ oops are

A. Functions preceding with virtual keywords.


B. Functions inherited from base class to derived class.
C. Two or more functions having same name but different number of parameters or type.
D. None of above

View Answer
Answer: C
Function overloading is compile time polymorphism in which 2 or more functions share the same name
with different arguments and parameters in C++ oops.
Recommended to read function overloading in C++

NOTE: In C++, constructor is also a special type of function that can be overloaded. You can
read advantage of constructor overloading in C++ applications.

Q) Correct way to declare pure virtual function in a C++ class is

A. virtual void foo() =0 ;


B. void virtual foo()= { 0 }
C. virtual void foo() {} = 0;
D. None

View Answer
Answer: A
A is the correct declaration of pure virtual function in a class in C++

Q) 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

View Answer
Answer: D

Both Car obj; and Car *obj = new Car() are valid way to create an object of the class.
Q) In C++, Class object created statically(e.g. Car obj; and dynamically (Car *obj = new Car() ; ) are
stored in memory

A. Stack, heap
B. Heap, heap
C. Heap, stack
D. Stack, stack

View Answer
Answer: A

Q) 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

View Answer
Answer: A

Q) In C++ programming, cout is a/an

A. Function
B. Operator
C. Object
D. macro

View Answer
Answer: C

Q) Which is Abstract Data Type in C++

A. Class
B. Int
C. Float
D. array

View Answer
Answer: A
Q) Class allows only one object of it to be created though out the program life cycle

A. Singleton class
B. Abstract class
C. Friend class
D. All classes

View Answer
Answer: A

Q) Statically allocated object for class A in C++ is

A. A *obj = new A();


B. A obj;
C. A obj = new A();
D. None

View Answer
Answer: B

Q) 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

View Answer
Answer: A

Q) 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

View Answer
Answer: B
Q) 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

View Answer
Answer: C

Q) 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

Q) 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

View Answer
Answer: C

Q) Which is used to define the member function of a class externally?

A. :
B. ::
C. #
D. None
View Answer
Answer: B

Q) In C++, an object cannot be created for

A. An interface
B. An Abstract class
C. A singleton class
D. A&B
E. A, B & C

View Answer
Answer: D

Q) By default functions available in C++ language are

A. Constructor
B. Destructor
C. Copy constructor
D. Assignment operator
E. All

View Answer
Answer: E

Q) The OOPs concept in C++, exposing only necessary information to users or clients is known as

A. Abstraction
B. Encapsulation
C. Data hiding
D. Hiding complexity

View Answer
Answer: A
Q) Which of the following is an abstract data type?

A. Class
B. Int
C. String
D. Double

View Answer
Answer: A

Q) Hiding the complexity is known as

A. Abstraction
B. Encapsulation
C. Data hiding
D. Composition

View Answer
Answer: B

Q) For Cat and Animal class, correct way of inheritance is

A. class Cat: public Animal


B. class Animal: public Cat
C. Both are correct way
D. None is correct way

View Answer
Answer: A

Q) In a class, encapsulating an object of another class is called

A. Composition
B. Inheritance
C. Encapsulation
D. None

View Answer
Answer: A
In simple word, if a class contains an object of another class as a data member, then it is known
as composition. For example,
Class Y, have a class X’s object as data member. Means, Y is composed of X.

class X {
public:
void f1() {

}
};
class Y{
X obj;//class object as a data member
public:
void f2() {

}
};

Another example,we can take that a house is composed of windows, door and bricks etc. So,
class House will look like below

class Door {

};
class Windows {

};
class Bricks {

};
class House{
Door _d;
Windows _w;
Bricks _b;

public:
void showHouse() {

}
};

Q) Features not available in C++ object oriented programming is

A. Virtual destructor
B. Virtual constructor
C. Virtual function
D. All
View Answer
Answer: B

There is no concept of virtual constructor available in C++. However, virtual destructor is


available in C++ language to maintain the destructor call from derived to base class. In
polymorphic classes, if we don’t use virtual destructor in base class then the derived class
destructor will not be called that may cause resource leaks. Recommended to read Why no
virtual constructor in C++ and complete detail of virtual destructor with example in C++,
it’s uses and how and when resources can leak etc.

Q) IS A relationship in C++ is

A. Inheritance
B. Encapsulation
C. Composition
D. None

View Answer
Answer: A

Q) If you want to write multiple functions in a class with same name, then what C++ feature will you
use?

A. Function overriding
B. Encapsulation
C. Function overloading
D. None

View Answer
Answer: C

Compile time polymorphism feature is used i.e. function overloading in C++. Function
overloading means, in a class, multiple functions with same name can be written with different
signatures, return types etc.

Q) Polymorphism types is/are

A. Compile time
B. Run time
C. Both
D. None

View Answer

Answer: C

Two types of Polymorphism are available in C++ object oriented programming i.e. compile time
and run time polymorphism. Also, known as early binding and late binding respectively.

Compiler time polymorphism features in C++ language are function overloading, constructor
and operator overloading etc. and run time polymorphism is function overriding in inheritance
relationship.

Q) If I want to have common functions in a class and want to defer implementations of some other
functions to derived classes, then we need to use

A. An interface
B. An abstract class
C. A friend class
D. A static class

View Answer
Answer: B

In C++ object oriented programming, abstract class is used for the same, in which we have
common or say generalized function in abstract base class and also may have pure virtual
function in this class that forces derived classes to implement it.

Read in detail about abstract class oops concepts with example in C++ and pure virtual
function used to create abstract class and interface in C++ language

Q) Not using virtual destructor feature in a C++ object oriented programing can cause

A. Memory leak
B. An Issue in creating object of the class
C. An issue in calling base class destructor
D. Nothing

View Answer
Answer: A

Virtual destructor is used to maintain the hierarchy of destructor calls for polymorphic classes in
inheritance. If we don’t use it then it may cause resource leak or memory leak. Read the all
concept of C++ virtual destructor. Know if it is necessary to write virtual destructor or when to
write etc.

Q) Which C++ oops feature is related to re-usability?

A. Encapsulation
B. Inheritance
C. Abstraction
D. None

View Answer
Answer: A
Inheritance feature is used for concept of code re-usability as in inheritance a class can inherit
properties and functions of existing well written class.
Abstraction : Provide only necessary information to client code.
Encapsulation: Hide complexity. e.g. by wrapping private class data members by functions. By making
internal function of a class private and using interfaces etc.

Q)base class and derived class relationship comes under

A. Inheritance
B. Polymorphism
C. encapsulation
D. None

Answer : A

Explanation: Base class and derived class come under inheritance, one of the C++ oops
principle. Also, it is known as parent child relationship.
Q) C++ Inheritance relationship is

A. Association
B. Is-A
C. Has-A
D. None

Answer:B

Explanation: IS A Relationship is related to inheritance in C++.


Lets consider a relation ship between classes i.e. Dog IS A Animal, Apple IS A Fruit, Car IS A
Vehicle etc. Here, IS A relationship is valid, but, if we say Animal IS A Dog, then it is wrong.
So, Animal class should be the base class and Dog class will be the derived class.

Q) Types of inheritance in C++ are

A. Multilevel
B. Multiple
C. Hierarchical
D. All the above

Answer: D

Explanation: All are types of inheritance relationship in C++ oops.


Multilevel Inheritance: When a class is derived from a class which is also derived from another
class.
Multiple Inheritance: A class inherits multiple class. or say, A class has more than one base
class.
Hierarchical Inheritance: When multiple classes derived from a same base class.

Q) Inheritance allow in C++ Program?

A. Class Re-usability
B. Creating a hierarchy of classes
C. Extendibility
D. All
Answer: D

Explanation: Advantage of inheritance are like re-usability- You can re-use existing class in a
new class that avoid re-writing same code and efforts.
We can make an application easily extensible.

Q) Functions that can be inherited from base class in C++ program

A. Constructor
B. Destructor
C. Static function
D. None

Answer:D

Explanation:

In C++, constructor and destruction of a class cannot be inherited to derived class. However,
when we create the object of derived class then constructor of the base class is called
automatically. You can read order of execution of constructors and destructors call in c++
inheritance.

Static function is not the part of an object, Hence, it cannot be inherited in derived classes. Note
that all the class member functions that are the part of an object, only they can be inherited. Read
what is static function in C++ programming

Q)____________ members of base class are inaccessible to derived class

A. Private
B. Protected
C. Public
D. None

Answer:A
Q) Accessing functions from multiple classes to a derived class is known as

A. multiple inheritance
B. single inheritance
C. Hybrid inheritance
D. multilevel inheritance

Answer:A

Q) In inheritance, order of execution of base class and derived class destructors are

A. Base to derived
B. Derived to base
C. Random order
D. none

Answer: B

In inheritance, execution order of constructors are always from base to derived and destructors
call order is in reverse i.e. from derived to base. In polymorphic classes, means the class that
contain virtual functions, we need to make destructor virtual in base class. Other wise the derived
class destructor will not be called. Read detail about C++ virtual destructor with example.

Q) Compile time polymorphism in C++ language are

A. Operator overloading
B. Function overloading
C. Function overriding
D. B Only
E. A&B

View Answer
Answer: E
Q) 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

View Answer
Answer: D

Q) 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

View Answer
Answer: C

Q) 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

View Answer
Answer: B

Q) Which of the following cannot be overloaded in C++?

A. Increment operator
B. Constructor
C. Destructor
D. New and delete operator

View Answer
Answer: C
Destructor of a class cannot be overloaded in C++ programming. Increment operator, constructor
and new and delete can be overloaded.

Q) Which is the correct declaration of pure virtual function in C++

A. virtual void func = 0;


B. virtual void func() = 0;
C. virtual void func(){0};
D. void func() = 0;

View Answer
Answer: B

virtual void func() = 0; is the correct declaration.

You can read in detail about pure virtual function in C++ and how we use pure virtual
function to create an interface in C++ program.

Q) In a class, pure virtual functions in C++ is used

A. To create an interface
B. To make a class abstract
C. To force derived class to implement the pure virtual function
D. All the above

View Answer
Answer: D

All are correct. Recommended to read abstract class in C++ with example that uses pure
virtual function.

Q) Which public member of a base class cannot be inherited?

A. Constructor
B. Destructor
C. Both A & B
D. Only B

View Answer
Answer: C

In C++ constructor and destructor both cannot be inherited to child class.


Q) How many VPTR is created internally for a base class and a derived class

A. 0
B. 1
C. 2
D. 3

View Answer
Answer: B

Q) Number of virtual table created for a base and a derived class is

A. 0
B. 1
C. 2
D. 3

View Answer
Answer: C

Q) 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

View Answer
Answer: B

C++ does not have keyword interface like C# or java. Pure virtual function is used to create
an interface in C++ programs.

Q) Which statements are true about an abstract class

A. Abstract class has at least one pure virtual function.


B. Pointer for an abstract class can be created
C. Object of an abstract class cannot be created.
D. All are correct.

View Answer
Answer: D

Q) Run time polymorphism in C++ Program is

A. New and delete operator overloading


B. ++ and – – operator overloading
C. :: operator overloading
D. None

View Answer
Answer: D

Q) Run time binding is related to

A. Function overriding
B. Operator overloading
C. A&B
D. None

View Answer
Answer: A

Q) Which function cannot be overloaded in C++

A. Constructor
B. Class destructor
C. Both a & b
D. None

View Answer
Answer: B

Destructor of a class cannot be overloaded. Read in detail in the interview question can we
overload destructor in C++ program?
Q) Operators can be overloaded in C++ is/are

A. New
B. Delete
C. ++
D. All can be overloaded

View Answer
Answer: D

Q) In C++ code , variables can be passed to a function by

A. Pass by value
B. Pass by reference
C. Pass by pointer
D. All the above

View Answer
Answer: D
In C++ programming, all pass by value, reference and pointer are used. Note that pass by reference in C
Programming language is not available. However, sometimes people use the term pass by reference
instead of pass by address or pass by pointers. Read here pass by value and pass by pointer in C
programming and difference between pass by pointer and pass by reference in C++ language.

Q) Constant function in C++ can be declared as

A. void display()
B. void display() const
C. const void display()
D. void const display()

View Answer
Answer: B

Constant function in a class is used to prevent modification of class member variables inside its
body. When we only want to read member variable and use it in function body with no
modification then we should use const function. Read detail of constant function in C++ object
oriented programming.
Q) True and false statements about inline function in given C++ code example is/are

(I)Static function of a class can be called by class name using scope resolution operator i.e. : :
(II)Static function can receive both static and non-static data members of a class
(III)Static function is not the part of an object of a class

A. I and II
B. I only
C. I and III
D. I, II and III

View Answer
Answer: C

Read in detail about static function in C++ with example and if static function can access
non static data in C++ program.

Q) Which of the following functions are provided by compiler by default if we don’t write in a C++
class?

A. Copy constructor
B. Assignment
C. Constructor
D. All the above

View Answer
Answer: D

Q) Which function can be called without using an object of a class in C++

A. Static function
B. Inline function
C. Friend function
D. constant function

View Answer
Answer: A
Q) True and false about inline function statements in C++
class A{
public:
void func1(){
}
void func2();
};
inline void A::func2(){

A. Func1 is inline function


B. Func2 only is inline function
C. Func1 and Func2 both are inline functions
D. None of the above is inline

View Answer
Answer: C

Q) Which function can be called without using an object of a class in C++

A. Virtual function
B. Inline function
C. Static function
D. constant function

View Answer
Answer: C

Q) Which of the following function declaration using default arguments is incorrect?

A. int foo(int x, int y =5, int z=10)


B. int foo(int x=5, int y =10, int z)
C. int foo(int x=5, int y, int z=10)
D. all are correct

View Answer
Answer: A
Explanation:Default arguments in a function in C++ program is initialized from right to left.
Q) Which function cannot be overloaded in C++ program?

A. Virtual function
B. member function
C. Static function
D. All can be overloaded

View Answer
Answer: C
Static functions cannot be overloaded in C++ programming. You can read static function in C++ and how
it differs from C.

Q) Choose the correct answer for following piece of C++ pseudo code
void func(int a, int &b)
{

int main(){
int a,b;
func(a,b);
}

A. a is pass by value and b is pass by reference


B. a is pass by reference and b is pass by value
C. a is pass by value and b is pass by address
D. a is pass by value and b is pass by pointer

View Answer
Answer: A
B parameter is not pass by address/pointer but reference. Here is the correct pseudo code for pass by
address or say pointer.

void func(int a, int *b)


{

int main(){
int a,b;
func(a,&b);
}
Read about difference between pointer and reference in C++

Q) Overloaded functions in C++ oops are

A. Functions preceding with virtual keywords.


B. Functions inherited from base class to derived class.
C. Two or more functions having same name but different number of parameters or type.
D. None of above

View Answer
Answer: C
Function overloading is compile time polymorphism in which 2 or more functions share the same name
with different arguments and parameters in C++ oops.
Recommended to read function overloading in C++

NOTE: In C++, constructor is also a special type of function that can be overloaded. You can
read advantage of constructor overloading in C++ applications.

Q) Correct way to declare pure virtual function in a C++ class is

A. virtual void foo() =0 ;


B. void virtual foo()= { 0 }
C. virtual void foo() {} = 0;
D. None

View Answer
Answer: A
A is the correct declaration of pure virtual function in a class in C++.

You might also like