C++ Multiple Choice Questions

MCQ Based on Basics of C++

1) #include<userdefined.h>

Which of the following is the correct syntax to add the header file in the C++ program?

  1. #include<userdefined>
  2. #include "userdefined.h"
  3. <include> "userdefined.h"
  4. Both A and B

Answer: D

Explanation: To include the herder files in the C++ program user can use any of the following given syntax.

Or


2) Which of the following is the correct syntax to print the message in C++ language?

  1. cout <<"Hello world!";
  2. Cout << Hello world! ;
  3. Out <<"Hello world!;
  4. None of the above

Answer: A

Explanation: To print the message in the C++ language user can use the following syntax:


3) Which of the following is the correct identifier?

  1. $var_name
  2. VAR_123
  3. varname@
  4. None of the above

Answer: B

Explanation: There are some certain rules that must be followed by the users while writing the identifiers.

  • It may contain uppercase/lowercase letters, digits, and underscore (_) only.
  • It always starts only with non-digit characters.
  • It should not contain any special characters like $, @etc

4) Which of the following is the address operator?

  1. @
  2. #
  3. &
  4. %

Answer: C

Explanation: To print the address of any variable, a user can use the "&" operator. To understand it more clearly, consider the following example:


5) Which of the following features must be supported by any programming language to become a pure object-oriented programming language?

  1. Encapsulation
  2. Inheritance
  3. Polymorphism
  4. All of the above

Answer: D

Explanation: There is nothing that forces a user to use the OOP concept in C++. In contrast, it is necessary for a programming language that it must support all three features as encapsulation, inheritance, and polymorphism completely to become a pure Object-Oriented Language.


6) The programming language that has the ability to create new data types is called___.

  1. Overloaded
  2. Encapsulated
  3. Reprehensible
  4. Extensible

Answer: D

Explanation: A language that can generate the new data types is known as the extensible languages as they can handle the new data types.


7) Which of the following is the original creator of the C++ language?

  1. Dennis Ritchie
  2. Ken Thompson
  3. Bjarne Stroustrup
  4. Brian Kernighan

Answer: C

Explanation: Bjarne Stroustrup creates C++ language during 1997 at AT&T Bell Labs.


8) Which of the following is the correct syntax to read the single character to console in the C++ language?

  1. Read ch()
  2. Getline vh()
  3. get(ch)
  4. Scanf(ch)

Answer: C

Explanation: The "cin.get()" is one of the several functions provided in C++ language that is used to read the single or multiple characters to console.


9) Which of the following statements is correct about the formal parameters in C++?

  1. Parameters with which functions are called
  2. Parameters which are used in the definition of the function
  3. Variables other than passed parameters in a function
  4. Variables that are never used in the function

Answer: A

Explanation: Parameters that are used in the body of the function are known as formal parameters. These parameters represent the parameters passed to the function and are only used inside the function's body.


10) The C++ language is ______ object-oriented language.

  1. Pure Object oriented
  2. Not Object oriented
  3. Semi Object-oriented or Partial Object-oriented
  4. None of the above

Answer: C

Explanation:

The common thing about the Pure Object-oriented language it provides three basic features like Inheritance, Encapsulation, and Polymorphism. Each programming language that supports these entire three features is known as the Pure-Object oriented language. Whereas if a programming language support all these three features but not support completely are known as the Partial-Object oriented languages or the Semi Object-oriented languages

The main reasons why the C++ programming language is Known as Semi-Object oriented language are as follows:

  1. Availability of the Friend function-
    A friend class is allowed to access private and protected members of another class, within which it is declared a friend. It may be very useful for some time, but still, it violates the rule of the Object-Oriented features.
  2. Concept of the Global variable-
    As we all know that we can declare a global variable in C++ language that can be easily accessible from anywhere within the program. So again, C++ does not provide complete privacy because no one is restricted to access and manipulate that data/information. Hence it offers partial Encapsulation, unlike Java Language, in which a user only allows to declare a variable within the class and can provide access specifier to it.
  3. The main function is Out-side the class-
    C++ is an object-oriented language, but still, object-oriented is not fundamentally related (or implicit) to the language. So a user can easily write a valid, well-defined C++ code even without using any object once.

11) Which of the following features is required to be supported by the programming language to become a pure object-oriented programming language?

  1. Encapsulation
  2. Inheritance
  3. Polymorphism
  4. All of the above

Answer: D

Explanation: There is nothing that forces a user to use the OOP concept in C++. In contrast, it is necessary for a programming language that it must support all three features of Encapsulation, Inheritance, and Polymorphism completely to become a Pure Object-Oriented Language.


12) Which of the following comment syntax is correct to create a single-line comment in the C++ program?

  1. //Comment
  2. /Comment/
  3. Comment//
  4. None of the above

Answer: A

Explanation: To create a single line comment (or one-line comment) in C++ program one can use the "// write comment" syntax. We can understand it more easily with the help of following given Program:

Example

Output

Welcome to Javatpoint

13) C++ is a ___ type of language.

  1. High-level Language
  2. Low-level language
  3. Middle-level language
  4. None of the above

Answer: C

Explanation: C++ contains the features of both types of high and Low-level programming languages, and it is also not wrong if we call it the combination of both high and low-level languages.


14) For inserting a new line in C++ program, which one of the following statements can be used?

  1. \n
  2. \r
  3. \a
  4. None of the above

Answer: A

Explanation:

To insert a new line or to jump on to the next line, one can use the "\n." In c++, there is also an alternative is available that is " endl," which is also used for breaking a line in the output. Let see the example of both the "\n" and "endl."

Example: Using "\n."

Output

Hello World!
I am learning C++

Example: With using "end"

Output

Hello World!
I am learning C++ 

15) Which one of the following represents the tab?

  1. \n
  2. \t
  3. \r
  4. None of the above

Answer: B

Explanation: The "\t" is a type of space sequence representing the tab, which means a set of blank space adds to the line. To understand it more clearly, consider the following example:

Program

Output

Enter the first number    12
Enter the second number    13
Greatest number is    13 

Set of MCQ Based on Arrays of the C++

1) Which of the following refers to characteristics of an array?

  1. An array is a set of similar data items
  2. An array is a set of distinct data items
  3. An array can hold different types of datatypes
  4. None of the above

Answer: A

Explanation: Basically, an array is a set of similar data items that are stored in the contiguous memory blocks. You can access any data item randomly using the index address of the element s.


2) If we stored five elements or data items in an array, what will be the index address or the index number of the array's last data item?

  1. 3
  2. 5
  3. 4
  4. 88

Answer: C

Explanation: The array uses the contiguous block of memory for storing the data elements. Hence the data items pushed into an array are stored at the continuous address space. The index number of the array begins with zero so, the first data item pushed into the array will be stored at zero and so on. Hence index number of the last (fifth) element will be 4.


3) Which of the following is the correct syntax for declaring the array?

  1. init array []
  2. int array [5];
  3. Array[5];
  4. None of the above

Answer: B

Explanation: To declare an array in C++, we first need to specify its data type according to requirements such as int or char, afterward that the array's name and the size of the array. So the correct answer will be B.

Example: Array declaration by specifying size and initializing elements

int arr[8] = { 10, 20, 30, 40 };

The compiler will create an array of size 8, initializes the first four elements as specified by the user and rest elements as 0

The above is just same as

"int arr[] = {11, 22, 32, 44, 0, 0,0,0}".

4) Which of the following is the correct syntax for printing the address of the first element?

  1. array[0];
  2. array[1];
  3. array[2];
  4. None of the above

Answer: A

Explanation: To print or access the first data item of the array, the correct syntax is "array[0];" because the array's index begins with zero instead of one. So the correct answer will be A.


5) Which of the following gives the 4th element of the array?

  1. Array[0];
  2. Array[0];
  3. Array[3];
  4. None of the above

Answer: C

Explanation: The index of the array begins with zero instead of 1. To print the 4th element of the array, the index number will be n-1 or (3);


6) What is the output of the given program?

  1. -15
  2. -30
  3. Compiler error
  4. Garbage value

Answer: B

Explanation: It will print the negative value of the specified values because the "-" sign we used while specifying the array elements. So the correct answer will be the "-30".


7) Which type of memory is used by an Array in C++ programming language?

  1. Contiguous
  2. None-contiguous
  3. Both A and B
  4. Not mentioned

Answer: A

Explanation: In the C and C++ programming language, the memory used by an array is usually contiguous, which means when an array is declared or initialized in the program a block of memory is selected form the memory space immediately. The major drawback of an array is that users have to guess the size of the array before actually using it, in which a significant amount of memory will be occupied even when it is not used. This later creates the problem of lack of memory.


8) Which of the following is the correct definition of sorting?

  1. Sorting is a type of process in which the data or information is ordered into a specific order. Example increasing orders, decreasing.
  2. Sorting information or data only in increasing order
  3. Sorting is a type of process in which data elements are modified or manipulated
  4. None of the above

Answer: A

Explanation: Sorting is a type of technique or process in which the locations of data elements hold by the array are reordered or manipulated. So the correct answer will be A.

For Example

Un-sorted Array

4321567

Sorted Array

1234567

9) How many types of the array are there in the C++ programming language?

  1. In the C++ programming language, there are three types of arrays
  2. In the C++ programming language, there are four types of arrays
  3. In the C++ programming language, there are two types of arrays
  4. Both A and B

Answer: C

Explanation: In the C++ programming language, there are mainly two types of arrays that are Single Dimension arrays and Multi-Dimension arrays. In Single-Dimension arrays, the same types of values are hold in the form of a List, while on the other hand, in Multi-Dimension arrays; values are stored in the form of a matrix.


10) In C++, for what purpose the "rank()" is used?

  1. It returns the size of each dimension
  2. It returns the maximum number of elements that can be stored in the array
  3. It returns the dimension of the specified array
  4. None of the above

Answer: C

Explanation: In C++, one can use the rank function where he wants to know about the dimensions( e.g., single-dimension, multi-dimension) of a specific array by just passing it to the "rank()" function.


11) Which one of the following is the correct definition of the "is_array();" function in C++?

  1. It checks that the specified variable is of the array or not
  2. It checks that the specified array of single dimension or not
  3. It checks that the array specified of multi-dimension or not
  4. Both B and C

Answer: A

Explanation: In C++, the "is_array();" is used for checking that the specified element or data item belongs to the array type or not.


12) Observer the given C++ program carefully and choose the correct output from the given options:

Program

  1. 110
  2. 001
  3. 010
  4. None of the above

Answer: C

Explanation: The correct output will be "010" Because in both cases, A and C variables passed to the "is_array()" function are different, so the function returns zero in both cases while in the case of B, they are the same. Hence it returns one as the output.


13) Read the given C++ program carefully and choose the correct output from the given options:

Program

  1. 121
  2. 321
  3. 123
  4. 010

Answer: C

Explanation: As we can see in the above program, here, the "rank()" function is used. The "rank()" function is used to know about the dimensions of the passed array. In case A the array passed to the "rank()" function is single-dimensional, In case B, the passed array is 2-dimensional, and in case C, the array passed is three-dimensional. So the output return by the "rank()" function is 123.


14) What did we call an array of the one-dimensional array?

  1. Single Dimensional array
  2. Multi-Dimensional array
  3. 2D Array (or 2-Dimensional array)
  4. Both A and B

Answer: C

Explanation: An array of one-dimensional array is known as the 2-dimensional array or 2D Array-like. We can understand it more clearly with the help of the following example:

Initialization of 2-Dimensional Array


15) Which types of arrays are always considered as linear arrays?

  1. Single-dimensional
  2. Multi-dimensional
  3. Both A and B
  4. None of the above

Answer: A

Explanation: Single-dimensional arrays are always considered as linear arrays.


16) Which of the following can be considered as the object of an array?

  1. Index of an array
  2. Elements of the Array
  3. Functions of the Array
  4. All of the above

Answer: B

Explanation: The elements in the array are known as the objects of the array.


17) How many types of elements can an array store?

  1. Same types of elements
  2. Char and int type
  3. Only char types
  4. All of the above

Answer: A

Explanation: An array can hold several elements except that all the data elements are of the same type.


18) Elements of a one-dimensional array are numbered as 0,1,2,3,4,5, and so on; these numbers are known as ____

  1. Subscript of Array
  2. Members of Array
  3. Index values
  4. Both A and C

Answer: D

Explanation: The elements of one-dimensional array are indexed as 0,1,2,3,... and these numbers are also known as the index values or subscripts of the array.


MCQ Based on the Oops Concepts of the C++

1) Which of the following statement is true about the new and malloc?

I. The "new" is a type of operator while "malloc" is a kind of function
II. "new" invokes a constructor, whereas "malloc" does not invoke the constructor
III. "malloc" returns void pointer and also needed to typecast whereas "new" returns required the pointer

  1. Only I
  2. Both I and II
  3. I, II, III
  4. None of the above

Answer: C

Explanation: All statements mentioned in the above question are completely true about the "malloc" and the "new." The "malloc" is a kind of function available in the C++ language, while the "new" is a type of operator that invokes the Constructor.


2) Which of the following statement is true about the new and malloc?

I. The pointer object initialization of a specific class using "malloc" also needs to include constructor calls; on the other hand, doing so with the "new" keyword does not include any constructor calls.
II. The pointer object initialization of a specific class using the "new" keyword also needs to include a constructor call. On the other hand, doing so with the "malloc" does not need to include any constructor calls.
III. Pointer object initialization of a specific class using either "new" or "malloc" involves the constructor call.

  1. Only II
  2. Both II and III
  3. Only I
  4. None of the above

Answer: A

Explanation: In object initialization of a class using the "new" keyword also involves a constructor call, while doing so with the "malloc" does not require any involvement of the constructor call. This is the main reason why the "new" is added explicitly in the C++ language. However, the "malloc" function is used to assign the memory to any specific pointer, so it assigns an equal amount of memory to the class size. At the same time, the "new" keyword involves the initialization, hence invokes the Constructor of that particular class.


3) Which of the following statement is correct about Virtual Inheritance?

  1. It is a technique to ensure that a private member of a base class can be accessed
  2. It is a technique to optimize the multiple inheritances
  3. It is a technique to avoid the multiple inheritances of the classes
  4. It is a C++ technique to avoid multiple copies of the base class into the derived or child classes

Answer: D

Explanation:


4) Which one of the following statements correctly refers to the Delete and Delete[] in C++ programming language?

  1. Delete is syntactically correct although, if the Delete[] is used, it will obtain an error.
  2. The "Delete" is used for deleting the standard objects, while on the other hand, the "Delete[]" is used to delete the pointer objects
  3. The "Delete" is a type of keyword, whereas the "Delete[]" is a type of identifier
  4. The "Delete" is used for deleting a single standard object, whereas the "Delete[]" is used for deleting an array of the multiple objects

Answer: D

Explanation: The "Delete" is used with the single general object, while on the other hand, the "Delete[]" is used with the array of the multiple objects initiated with the new operator.


5) Consider the following given program and choose the most appropriate output from the given options:

  1. Segmentation failure.
  2. Error.
  3. The Constructor will be invoked five times, and after that destructor will be invoked only once.
  4. The Constructor will be invoked five times, and after that destructor will also be invoked five times.

Answer: D

Explanation: As mentioned in the above-given program, five-pointer variables are initiated using the "new" keyword so that the Constructor will be invoked five times. In addition, the destructor "Delete[]" is used( that is used for deleting the group of the several objects) for terminating variables. Hence all of the variables will be terminated completely, and while terminating the variables, the destructor will be invoked five times.


6) Consider the following given program and choose the most appropriate output from the given options:

  1. Constructing base, Constructing Derived, Destructing Base, Destructing Derived
  2. Constructing base, Constructing Derived, Destructing Base
  3. Constructing base, Constructing Derived, Destructing Derived, Destructing Base
  4. None of the above

Answer: B

Explanation: In the above-given program, the derived class's object is storing in the base class pointer; while the object is destroyed, the program has never invoked the destructor of the Derived class. Therefore, it shows that the object is not destroyed at all; hence, in this case, the program may also behave undesirably.


7) Which of the following can be considered as the correct syntax for declaring an array of pointers of integers that has a size of 10 in C++?

  1. int arr = new int[10];
  2. int *arr = new int*[10]
  3. int **arr = new int*[10];
  4. int *arr = new int[10];

Answer: C

Explanation: To declare an array of integers' pointer, here we need to use the double-pointer array where every element is set of the pointer to the integers. Therefore the correct option is C.


8) Which of the following can be considered as the members that can be inherited but not accessible in any class?

  1. Public
  2. Protected
  3. Private
  4. Both A and C

Answer: C

Explanation: The "Private" member of a class can be inherited by the child class. Still, the child class cannot access them (Or we can say that they are not accessible from the child class).


9) Which of the following can be used to create an abstract class in the C++ programming language?

  1. By using the pure virtual function in the class
  2. By declaring a virtual function in the base class
  3. By declaring the virtual keyword afterward, the class Declaration
  4. None of the above

Answer: A

Explanation: A class must contain at least one declaration of the pure virtual function in itself to be called an abstract class. Therefore to make an abstract class, one has to declare at least one pure virtual function in that class.


10) Which of the following statements is correct about the class?

  1. An object is an instance of its class
  2. A class is an instance of its object
  3. An object is the instance of the data type of that class
  4. Both A and C

Answer: A

Explanation: Generally, an object is an instance of a class, e.g., an object represents the class.


11) Which of the following statements is correct about the friend function in C++ programming language?

  1. A friend function is able to access private members of a class
  2. A friend function can access the private members of a class
  3. A friend function is able to access the public members of a class
  4. All of the above

Answer: D

Explanation: A friend function can access any member of a class without caring about the type of member it contains, such as public, private, and protected.


12) Which of the following statement is not true about C++?

  1. Members of a class are public by default
  2. A class cannot have the private members
  3. A structure can have the member functions
  4. All of the above

Answer: C

Explanation: In C, structures are not allowed to have member functions; while on the other hand, C++ allows the structure to have the member functions. Members of the class are generally private by default, and those of the structures are public. So it is a completely false statement that classes can not private members.


13) Which of the following given statement is completely true?

I. In an object-oriented programming language, all the function calls are resolved at compile-time.
II. In a procedure programming language, all the function calls are resolved at compile-time

  1. Only II
  2. Only I
  3. Both I & II
  4. None of the above

Answer: B

Explanation: In a procedure programming language such as C, we do not have the concept of Polymorphism, so all function calls are resolved at the compile-time while, on the other hand, In an Object-Oriented language, through the concept of Polymorphism, all function calls cannot be resolved at the compile-time.


14) Which one of the following cannot be used with the virtual keyword?

  1. Constructor
  2. Destructor
  3. Member function
  4. None of the above

Answer: A

Explanation: In C++, we cannot use the virtual keyword with the Constructor because constructors are generally defined to initialize the object of a specific class; hence no other class requires the other class's object.


15) Which of the following is used for implementing the late binding?

  1. Operator Functions
  2. Constant Functions
  3. Virtual Functions
  4. Both A and B

Answer: C

Explanation: A virtual function can be used for implementing the concept of late binding. For example - Binding the actual functions to their corresponding calls.


16) Which of the following statements supports that reusable code should be one of the desirable features of any language?

  1. It helps in reducing the maintenance cost
  2. It helps in reducing the testing time
  3. It helps in reducing both the maintenance time and testing time
  4. It helps in reducing the compile time

Answer: C

Explanation: While reusing the existing code, we are not required to test/check that code, again and again, because it was already tested while it was written for the very first time. So the reusing the code defiantly helps in reducing the maintenance and testing time.

While reusing the existing code, the compile-time most likely to be increased or remain the same, and it is obvious because we use the existing code in our program to save our time( or to include any specific functionality) by which the size of the overall program gets grows which is natural.


50) Which of the following statement is correct about the C++ programming language?

  1. In C++, both the Static and Dynamic type checking are allowed
  2. In C++, member function are allowed to be of the type canst
  3. In C++, Dynamic checking is allowed
  4. None of the above

Answer: A

Explanation: In C++, both types of static and dynamic checking are allowed.


18) Which of the following is not a kind of inheritance?

  1. Distributed
  2. Multiple
  3. Multi-level
  4. Hierarchal

Answer: A

Explanation: Among the above options, Distributed is only, which is not a type of inheritance, while Multiple, Multi-level, and the Hierarchal are the types of inheritance.


19) What will happen if "In a C++ program a class has no name"?

  1. It is not even allowed in C++
  2. It will not have the Constructor
  3. It will not have the destructor
  4. Both B and C

Answer: C

Explanation: In the C++ program, if we use a class without assigning a name. As a result, it will not be going to have a destructor, but it will have the object. To understand it in more detail, consider the following program:

Program

#include 
using namespace std;
class
{
    public:
	void func()
        {
		cout<<"Hello world";
	}
}a;
int main(int argc, char const *argv[])
{
	a.func();
	return 0;
}

20) Which type of approach is used by the C++ language?

  1. Right to left
  2. Left to right
  3. Top to bottom
  4. Bottom-up

Answer: D

Explanation: Generally, C++ uses the Bottom-up approach while other programming languages like C use the top-down approach.


21) Which of the following concept refers to adding new components to the program at the run time?

  1. Dynamic Loading
  2. Dynamic binding
  3. Data hiding
  4. Both A & B

Answer: C

Explanation: The dynamic loading is referred to as the concept of adding a new component to the program as it runs.


22) How can one implement the compile-time Polymorphism in the C++ programming language?

  1. By using the Template
  2. By using the concepts of inheritance
  3. By using both the virtual functions and inheritance
  4. By using only the virtual functions

Answer: A

Explanation: One can easily implement the Compile-time Polymorphism using the Template.


23) How can one implement the run-time Polymorphism in the C++ programming language?

  1. By using the Template
  2. By using the concepts of inheritance
  3. By using both the virtual functions and inheritance
  4. By using only the virtual functions

Answer: In C++, one can implement the run-time Polymorphism by using the virtual functions and inheritance where the object decides which function to call.

Explanation: C


24) Which of the following offers a programmer the facility of using a specific class object into other classes?

  1. Polymorphism
  2. Abstraction
  3. Inheritance
  4. Composition

Answer: D

Explanation: The composition is referred to as the concept of using objects of a specific class into several other classes.


25) Which one of the following cannot be a friend in C++ languages?

  1. A Class
  2. A Function
  3. An Object
  4. None of the above

Answer: C

Explanation: In general, an object of any class cannot be a friend of the same and any other class as well. However, there are some functions, operator, and classes which can be made a friend.


26) How are the references different from the pointer?

  1. A reference cannot be modified once it initialized
  2. There is no need of an extra operator for dereferencing of a reference
  3. A reference cannot be NULL
  4. All of the above

Answer: D

Explanation: These are some basic reasons why the references are far different from the pointers.

In the case of pointers "*" operator is required for dereferencing the value contain by it. However, the reference does not need any type of operator for deference.

A Reference cannot be modified once it is initialized, but it is possible to do so in the case of a pointer.

A pointer can be made Null, whereas a reference cannot be NULL.


27) Among the following given options, which can be considered as a member of a class?

  1. Class variable
  2. Member variable
  3. Class functions
  4. Both A and B

Answer: B

Explanation: Generally, the functions of any class are also considered as the member function of that class.


28) Which of the following refers to the wrapping of data and its functionality into a single individual entity?

  1. Modularity
  2. Abstraction
  3. Encapsulation
  4. None of the above

Answer: C

Explanation: In C++, the property of wrapping the data and its functionality into a single entity is known as Encapsulation ( e.g., Classes).


29) Which of the following refers to using the existing code instead of rewriting it?

  1. Inheritance
  2. Encapsulation
  3. Abstraction
  4. Both A and B

Answer: A

Explanation: With the help of the inheritance concept, one can use existing code instead of rewriting. We can do this by inheriting the properties of pre-written code in other parts of the code blocks. Therefore the user is not required to write the same code repeatedly.


30) Among the following, which shows the Multiple inheritances?

  1. X,Y->Z
  2. X->Y->Z
  3. X->Y;X->Z
  4. None of the above

Answer: A

Explanation: In multiple inheritances, a single class can inherit properties form more than one base class.


31) Which of the following statements is true about the C++ programming language?

  1. C++ is an object-oriented programming language
  2. C++ is a procedural programming language
  3. C++ is a functional programming language
  4. C++ is both procedural and object-oriented language

Answer: D

Explanation: C++ is a type of programming language which supports both the procedural ( or step by step instructions) and object-oriented through the concept of classes.


32) Among the following, which statement is correct about the Modularity?

  1. Modularity means hiding the parts of the program
  2. Modularity refers to dividing a program into subsequent small modules or independent parts
  3. It refers to overloading the program's part
  4. Modularity refers to wrapping the data and its functionality into a single entity

Answer: B

Explanation: Modularity refers to dividing a program into small independent code blocks or modules so that they can be easily called anywhere in the entire program where it is required. The concept of Modularity is very efficient and helpful for developers because it makes the program well structured and easy to understand. Hence the correct option is D.


33) Read the following program carefully and find out which concept from the given options is not used or missing in the following program?

Program

  1. Polymorphism
  2. Encapsulation
  3. Inheritance
  4. Abstraction

Answer: A

Explanation: As we can see in the above-given program, the variables X and Y both are private members, which means they both are hidden from the outside world of the class, so here the concept of abstraction is used.

The other data members and their corresponding functions are stored in an individual class, so here the concept of Encapsulation is also used. In addition, Class B is derived from Class A, which means the concept of inheritance is used as well, but still, we didn't find and an overloaded function in any of the classes. Therefore the concept of Polymorphism is missing or not used in the given program.


34) Which of the following options correctly explains the concept of Polymorphism?

a.

b.

c.

d. None of the above

Answer: A

Explanation: The concept of Polymorphism refers to the overloading a function by changing either its number of passed arguments or changing its type. So you have only two options in which the function has named the same. Therefore one can easily find out that in option C, the type and the number of the argument all are the same, which definitely leads to an error that is wrong. However, the option in which the name of the function is the same has a different number of arguments, or different types is the correct option. So the correct answer is A.


Next TopicC++ MCQ Part 2