0% found this document useful (0 votes)
10 views12 pages

C++ Test2 03-07-2025

The document contains a series of multiple-choice questions related to C++ programming concepts, including inheritance, access modifiers, function overloading, pointers, and constructors. It tests knowledge on various topics such as object-oriented programming principles, data types, and syntax rules. Each question provides four options, with some questions focusing on specific C++ features and terminology.

Uploaded by

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

C++ Test2 03-07-2025

The document contains a series of multiple-choice questions related to C++ programming concepts, including inheritance, access modifiers, function overloading, pointers, and constructors. It tests knowledge on various topics such as object-oriented programming principles, data types, and syntax rules. Each question provides four options, with some questions focusing on specific C++ features and terminology.

Uploaded by

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

1. Which of the following operators is used in inheritance?

A. :
B. ::
C. >
D. ;

2. Which of the following is not a keyword?


A. sizeof
B. new
C. class
D. room

3. Which of the following statements is correct?


A. Base class can be inherited
B. Base class cannot have constuctor
C. Base class always needs to have three function
D. Pointer cannot be created in base class

4. Which of the following is not an access modifier?


A. public
B. protected
C. confidential
D. private
5. Setters and getters uses the concept of
A. encapsulation
B. abstraction
C. inheritance
D. polymorphism

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

7. Which symbol is used to get the address of an actual variable?


A. $
B. ^
C. &
D. -
8. How many instances of a class can be created?
A. 2
B. 5
C. 0
D. infinite

9. Which of the following is not a pillar of OOP?


A. Polymorphism
B. Abstraction
C. Inheritance
D. Manipulation

10. Which of the following concepts of OOPS means exposing only necessary
information to client?
A. polymorphism
B. Abstraction
C. Data hiding
D. Data manipulation
11. Which of the following is correct concerning pointers?
A. A pointer stores the address of an actual variable
B. A pointer stores the value as well as the address of an actual variable
C. A pointer should always point to integer
D. All of the above.

12. cout\~is a/an __________ in iostream.


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

13. cin is
A. variable
B. built-in function
C. user-defined function
D. constructor

14. Which of the following function is not a correct overload of \par


int add()?
A. double add()
B. float add(int a, int b)
C. float add(double a, int b)
D. float add(int a, string a)

15. Which of the following is not a data type?


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

16. Which of the following is an abstract datatype


A. class
B. function
C. variable
D. operator

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.

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


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

19. Which of the following is not a constrol structure used in c++?


A. Iteration
B. Decision
C. Sequence
D. Transformation

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.

21. Which of the following is correct about class?


A. class can have member functions.
B. class data members are public by default.
C. classes cannot be used after declaration.
D. class data members are private by default.

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

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 using
24. Which of the following operators cannot be overloaded?
A. +
B. .
C. ++
D. --

25. Which of the following is the correct class of the object cout?
A. iostream
B. istream
C. ofstream
D. ifstream

26. Which of the following is not a headerfile in c++


A. string
B. iostream
C. ifstream
D. destruction

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


A. Construct a new class
B. construct a new variable
C. constructs an index of an array
D. Initialize objects of a class

28. Which of the following causes a syntax error?


A. Missing semicolon in statement in\~main().
B. A problem in calling function.
C. adding parameters to int main() function
D. storing a string in an integer

29. Which of the following best describes polymorphism?


A. single value
B. several values
C. single form
D. multiple forms

30. Which of the following is the correct way of declaring a function as constant?
A. const int ShowData;
B. int const ShowData;
C. int ShowData(void) const;
D. Both A and B

31. Which of the following is a predirective used to declare a constant?


A. #declare
B. #define
C. #use
D. #parse

32. Which of the following is not a keyword in c++?


A. operator
B. new
C. slap
D. both b and c

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

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

35. Which of the following is a mechanism used to store a number of values of the
same type?
A. function
B. array
C. variable
D. class

36. Which of the following is correct about the statements given below?All
operators can be overloaded
in C++.We can change the basic/original 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.
37. Which of the following cannot be overloaded?
A. class
B. function
C. constructor
D. operator

38. Which of the following are only accessible inside a class?


A. Public data members
B. Private data members
C. public member functions
D. all of the above
39. Which of the following is not a type of inheritance?
A. Multiple
B. Multilevel
C. Distributive
D. Hierarchical

40. Which of the following operators cannot be overloaded?


A. +
B. ->
C. ?:
D. -
41. The child class inherits only the public members from its base class
A. true
B. false

42. Which of the following statements regarding functions is correct?


A. they can be called any number of times
B. they cannot be overloaded
C. They should always contain parameters.
D. Both A and C.

43. Which one of the following return types is used for a setter?
A. void
B. bool
C. int
D. none of the above

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

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


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

46. What will happen if a function is not having any name or identifier?
A. It cannot have a destructor.
B. It cannot have a constructor.
C. It is not allowed.
D. Both A and B.

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

48. Which of the following is not a iteration construct in c++?


A. for(;;)\par
\{\par
\}
B. foreach(;;)\par
\{\par
\}
C. do\par
\{\par
\}\par
while();
D. while\par
\{\par
\}

49. Which of the following is not access modifier?


A. public
B. private
C. protected
D. close

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

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


A. Class member variables are initialized using a constructor
B. Class members are private by default.
C. Class members are public by default.
D. Structure members are private by default.

52. Which of the following is used to make a class?


A. by using the class keyword before identifier
B. by using the class keyword after identifier
C. Making at least one member function private
D. Making at least one member function public

53. Which of the following access modifier is used as a default in a class


definition?
A. protected
B. public
C. private
D. friend

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

55. Which of the following provides a reuse mechanism?


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

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

57. Which of the following statement is not correct?


A. A poiner stores an address.
B. A pointer uses the * operator to access the value at the address stored in it
C. A pointer is declared with a datatype
D. A pointer is stored on external storage device

58. Which of the following statements is correct?1.Once a pointer variable has been
defined to point to
a particular variable it can refer to any other variable.2.A pointer cannot be used
in a class.
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

59. Functions can be declared to return a reference type. There are reasons to make
such a
declaration/Which of the following reasons are correct?
1.The information being returned is a large enough object that returning a
reference is more efficient
than ret
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

60. Which of the following statements is correct?1. An array can be declared with
number of
dimensions.2.We can create an array of pointers.
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
61. Which of the following statement is correct about the array?
A. A pointer must always be initialized within functions.
B. A pointer must always be initialized outside all functions
C. A pointer must always be initialized.
D. none of the above

62. A pointer is declared using the _____ symbol.


A. ?
B. ^
C. *
D. &

63. Which type of inheritance can the child class inherit from more than one base
class?
A. multple inheritance
B. hybrid inheritance
C. multi-level inheritance
D. both a and b

64. Which of the following statements is correct?


1.A reference is not a constant pointer.
2.A referenced is automatically de-referenced.
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

65. Which of the following statements is correct?


1.An array of references is acceptable.
2.We can also create a reference to a reference.
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

66. Which of the following statements is correct?


1.Once the variable and the reference are linked they are tied together.
2.Once the reference of a variable is declared another reference of that variable
is not allowed.
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

67. Which of the following statements is correct?


1.We can return a global variable by reference.
2.We cannot return a local variable by reference.
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

68. Reference is like a _____.


A. Pointer
B. Structure
C. Macro
D. Enum

69. Which of the following statement is correct?


A. A reference is a constant pointer.
B. A reference is not a constant pointer.
C. An array of references is acceptable.
D. It is possible to create a reference to a reference.

70. Which of the following statement is correct?


A. An array is declared using\~[] operator after the name.
B. Once a pointer variable has been defined to refer to a particular variable it
can refer to any other
variable.
C. A pointer must always be initialized within classes.
D. A variable can have multiple classes.

71. Which of the following statement is correct?


A. An array of boolean variables is acceptable
B. An array of arrays is acceptable.
C. An array of pointers is not acceptable.
D. Reference is like a structure.

72. Which of the following statements is correct?1.Pointer to pointer is not


allowed in c++. 2. Pointers
can only be used in classes.
A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.

73. A constructor that accepts __________ parameters is called the default


constructor.
A. one
B. two
C. zero
D. three

74. What happens when a class with parameterized constructors and having no default
constructor is
used in a program and we create an object that needs a zero-argument constructor?
A. Compile-time error.
B. Preprocessing error.
C. Runtime error.
D. Runtime exception.

75. Can a class have more than one constructor?


A. Yes
B. No

76. Destructor has the same name as the constructor and it is preceded by ______ .
A. !
B. ?
C. ~
D. $

77. For automatic objects, constructors and destructors are called each time the
objects
A. enter and leave scope
B. inherit parent class
C. are constructed
D. are destroyed

78. Which function is designed to initialize the value of member variable?


A. constructor
B. class
C. function
D. variable

79. Which of the following statement is correct?


A. Constructor has the same name as that of the class.
B. function should always have the same name as that of the class.
C. Both A and B.
D. variables have the same name as the first member function of the class.

80. Which of the following statement is incorrect?


A. Constructor is a special member function in the class.
B. The compiler always provides a used defined constructor.
C. It is necessary that a constructor in a class should always have return value
D. Both B and C.

81. When are the object's member variable initialized?


A. when the object is created
B. When the program terminates.
C. When any function in the object is called
D. As soon as local objects die.

82. Which of the following is not logical operator?


A. AND
B. NOT
C. XOR
D. OR
83. A function with the same name as the class is called __________ of that class.
A. constructor
B. destructor
C. function
D. object

84. Which of the following header files contains the function pow()?
A. math
B. calc
C. arithmetic
D. equation

85. Which of the following gets called when an object is created?


A. constructor
B. destructor
C. main
D. virtual function

86. Which of the following is not a header file in c++?


A. iostream
B. string
C. stdlib
D. stdbook

87. __________ is used to initialize the member variables of a class.


A. constructor
B. destructor
C. functions
D. constant

88. Which of the following function prototype is perfectly acceptable?


A. int Function(Function(int));
B. float Function(int Tmp = Show(int, float));
C. Both A and B.
D. float = Show(int a, int b);

89. Which of the following statement is correct?


A. C++ enables to define functions that take constants as an argument.
B. C++ is an object-oriented programming language
C. Both A and B.
D. We cannot have parameters while defining the function.
90. Which of the following statement is correct?
A. Overloaded functions can have at most one argument.
B. An overloaded function cannot have argument.
C. All arguments of an overloaded function can be of the same datatype
D. A function if overloaded more than once cannot have argument.

91. Which of the following statement is correct?


A. Two functions having same number of argument, order and type of argument can be
overloaded if
both functions do not have any default argument.
B. Overloaded function must have default arguments.
C. Overloaded function must have default arguments starting from the left of
argument list.
D. A function can be overloaded more than once.

92. Which of the following statement will be correct if the function has three
arguments passed to it?
A. The trailing argument will be the default argument.
B. The first argument will be the default argument.
C. The middle argument will be the default argument.
D. All the argument will be the default argument.

93. Which of the following statement is incorrect?


A. C++ is an object-oriented programming language
B. C++ uses a compiler
C. C++ is mark-up language
D. C++ is an all purpose language
94. Which of the following statement is correct?
A. Constructors can have default parameters.
B. Constructors cannot have default parameters.
C. Constructors can have any name apart from the class name
D. Constructors can have at most five default parameters.

95. Which of the following function cannot be an overloaded of the following?\par


int greaterThan()\par
\{\par
return 1;\par
\}
A. double greaterThan(int a, int b)
B. float greaterthan(int x)
C. stirng greaterThan(float * ip)
D. none of the above

96. Which of the following function declaration is/are incorrect?


A. int Sum(int a, int b, int c);
B. int Sum(int b, int b);
C. int Sum(void a = 0, int b, int c = 3);
D. Both B and C are incorrect.

97. Which of the following statement is incorrect?


A. The default value for an argument can be a global constant.
B. The default arguments are given in the function prototype.
C. Compiler uses the prototype information to build a call, not the function
definition.
D. The default arguments are given in the function prototype and should be repeated
in the function
definition.

98. Which of the following is a ternary operator in c++?


A. ?:
B. >
C. <
D. !=

99. Which of the following is not an unary operator in c++?


A. ++
B. sizeof()
C. --
D. <>

100. Which of the following is not keyword used in c++?


A. old
B. new
C. break
D. continue

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

102. How can we make a class inherit from another class?


A. By making all member functions constant.
B. By adding a colon followed by the name of the class it is inheriting from
C. By declaring it abstract using the static keyword.
D. By declaring it public followed by the name of a constructor

103. Which of the following statements is correct when a class is inherited


publicly?
A. Public members of the base class become protected members of derived class.
B. Public members of the base class become private members of derived class.
C. Private members of the base class become protected members of derived class.
D. Public members of the base class become public members of derived class.

104. Which of the following statements is correct about constructors?


A. Constructors cannot take any arguments
B. A constructor's name can be different from the class name
C. Constructors are called when an object is instantiated
D. Constructors can return a value

105. Which of the following access specifies is used in a class definition by


default?
A. Protected
B. Public
C. Private
D. Friend

106. Which of the following statement is incorrect with respect to a class?


A. Classes can contain both variables and functions.
B. A class takes a statement terminator at the end
C. An instance of a class is called an object
D. We can use friend keyword as a class name

107. Which of the following keywords is an access modifiers?


A. Confidential
B. Break
C. New
D. Public

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy