Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which is used to check the error in the block?(a) try(b) throw(c) catch(d) handlerI have been asked this question during an online exam.I'm obligated to ask this question of Catching Exceptions topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right choice is (a) try

Easy EXPLANATION - The try block is used to check for ERRORS, if there is any ERROR MEANS, it can throw it to CATCH block.

52.

Which is used to throw a exception?(a) throw(b) try(c) catch(d) handlerThe question was asked during an interview.I'm obligated to ask this question of Error Handling topic in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The correct ANSWER is (a) THROW

The EXPLANATION: throw keyword is USED to throw an exception.

eg:

53.

Which keyword is used to handle the expection?(a) try(b) throw(c) catch(d) handlerThe question was asked during an online interview.Enquiry is from Error Handling in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct ANSWER is (C) catch

Best EXPLANATION: When we found a exception in the program, We NEED to throw that and we handle that by USING the catch keyword.

54.

What is the Standard Template Library?(a) Set of C++ template classes to provide common programming data structures and functions(b) Set of C++ classes(c) Set of Template functions used for easy data structures implementation(d) Set of Template data structures onlyThe question was posed to me in an interview for internship.My question comes from Standard Template Library in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct option is (a) Set of C++ template classes to provide common programming data STRUCTURES and functions

The explanation is: STL expanded as STANDARD Template LIBRARY is set of C++ template classes to provide common programming data structures and functions.

55.

What should be the name of the constructor?(a) same as the object(b) same as the member(c) same as the class(d) same as the functionI have been asked this question in an interview.I need to ask this question from Class Hierarchies and Abstract Classes in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT ANSWER is (C) same as the class

For explanation: CONSTRUCTOR name should be same as the class name.

56.

Which class is used to design the base class?(a) abstract class(b) derived class(c) base class(d) derived & base classThe question was asked during an interview.I need to ask this question from Abstract Classes topic in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right OPTION is (a) abstract class

For EXPLANATION: Abstract class is USED to design base class because functions of abstract class can be OVERRIDDEN in DERIVED class hence derived class from same base class can have common method with different implementation, hence forcing encapsulation.

57.

What is the use of RAII in c++ programming?(a) Improve the exception safety(b) Terminate the program(c) Exit from the block(d) Crash the compilerThe question was posed to me in examination.Enquiry is from Error Handling Alternatives topic in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right OPTION is (a) IMPROVE the exception SAFETY

Easy EXPLANATION - RAII is used to improve the exception safety.

58.

Which type of program is recommended to include in try block?(a) static memory allocation(b) dynamic memory allocation(c) const reference(d) pointerI had been asked this question in an online interview.The origin of the question is Exceptions That Are Not Errors topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The correct ANSWER is (B) dynamic memory allocation

The explanation: While during dynamic memory allocation, Your system may not have sufficient resources to handle it, So it is better to USE it INSIDE the try block.

59.

When do we call that resource is leaked?(a) Arise of compile time error(b) It cannot be accessed by any standard mean(c) Arise of runtime error(d) It can be accessed by any standard meanThis question was addressed to me in quiz.Question is taken from Resource Management topic in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The correct choice is (B) It cannot be ACCESSED by any standard mean

The EXPLANATION is: Resource is said to be LEAKED when it cannot be accessed by any means of standard mean.

60.

How do define the user-defined exceptions?(a) inheriting and overriding exception class functionality(b) overriding class functionality(c) inheriting class functionality(d) delting and adding class memberI have been asked this question at a job interview.This intriguing question comes from Error Handling in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right CHOICE is (a) inheriting and overriding exception CLASS functionality

Best explanation: User defined EXCEPTIONS can be done by inheriting and overriding the exception class functionality.

61.

What are Iterators?(a) Iterators are used to iterate over C-like arrays(b) Iterators are used to iterate over pointers(c) Iterators are used to point memory addresses of STL containers(d) Iterators are used to iterate over functionsI got this question in a job interview.Origin of the question is Standard Template Library in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT answer is (c) ITERATORS are used to point memory addresses of STL containers

The best explanation: In C++, Iterators are provided to ITERATE over the STL containers.

62.

Which is dependant on template parameter?(a) base class(b) abstract class(c) method(d) static classThe question was asked in quiz.This interesting question is from Derivation and Templates in division Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct option is (a) base CLASS

Explanation: Base class is DEPENDANT on TEMPLATE PARAMETER.

63.

How many types of templates are there in c++?(a) 1(b) 2(c) 3(d) 4I got this question during an interview for a job.Question is taken from Simple String Template topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct answer is (b) 2

To explain I would SAY: There are two TYPES of TEMPLATES. They are FUNCTION template and class template.

64.

How many ways of reusing are there in the class hierarchy?(a) 1(b) 2(c) 3(d) 4This question was addressed to me during an online exam.My doubt is from Design of Class Hierarchies topic in division Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT choice is (B) 2

Easiest explanation - CLASS hierarchies PROMOTE reuse in two WAYS. They are code sharing and interface sharing.

65.

An uncaught handler returns to _______________(a) main function(b) its caller(c) its callee(d) waits there for some timeThe question was posed to me during an interview for a job.This intriguing question comes from Exception Handling topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right ANSWER is (c) its callee

To EXPLAIN I would say: Uncaught HANDLER returns to its callee(i.e. the FUNCTION it is CALLED by).

66.

Which of the following is an exception in C++?(a) Divide by zero(b) Semicolon not written(c) Variable not declared(d) An expression is wrongly writtenI had been asked this question in an interview.I would like to ask this question from Exception Handling topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer» CORRECT answer is (a) Divide by ZERO

Best explanation: EXCEPTIONS are those which are encountered during run-time of the program. semicolon, variable not declared and the wrong expression are compile-time ERRORS, therefore, they are not exceptions. Divide by zero is the PROBLEM that is encountered during run-time, therefore, it is an exception.
67.

Why we use :: template-template parameter?(a) binding(b) rebinding(c) both binding & rebinding(d) reusingI got this question during a job interview.The origin of the question is Template Arguments to Specify Policy Usage topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer» CORRECT option is (c) both binding & rebinding

To explain I would SAY: It is USED to adapt a policy into binary ONES.
68.

What are Templates in C++?(a) A feature that allows the programmer to write generic programs(b) A feature that allows the programmer to write specific codes for a problem(c) A feature that allows the programmer to make program modular(d) A feature that does not add any power to the languageI got this question in exam.This intriguing question originated from Function Templates topic in division Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct ANSWER is (a) A feature that allows the programmer to WRITE generic programs

Best EXPLANATION: Templates are features in C++ that allows the programmer to write generic programs. for example, MAKING the same function to take different types of arguments and perform the same ACTION on them without specifying the type in the argument list.

69.

How many types of the constructor are there in C++?(a) 1(b) 2(c) 3(d) 4This question was addressed to me in semester exam.I need to ask this question from Class Hierarchies and Abstract Classes topic in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT choice is (c) 3

The EXPLANATION is: There are THREE types of constructor in C++. They are the Default constructor, PARAMETERIZED constructor, COPY constructor.

70.

What is meant by exception specification?(a) A function is limited to throwing only a specified list of exceptions(b) A catch can catch all types of exceptions(c) A function can throw any type of exceptions(d) A try can catch all types of exceptionsThis question was posed to me during a job interview.This key question is from Exception Specifications topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct choice is (a) A function is LIMITED to THROWING only a SPECIFIED list of EXCEPTIONS

Easiest EXPLANATION - C++ provides a mechanism to ensure that a given function is limited to throwing only a specified list of exceptions. It is called an exception specification.

71.

Which statement is used to catch all types of exceptions?(a) catch()(b) catch(Test t)(c) catch(…)(d) catch(Test)I got this question in an interview.The question is from Exceptions That Are Not Errors topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The correct CHOICE is (C) catch(…)

Easy explanation - This catch statement will catch all TYPES of EXCEPTIONS that arises in the PROGRAM.

72.

Where exception are handled?(a) inside the program(b) outside the regular code(c) both inside or outside(d) main programI had been asked this question during an interview.My question comes from Catching Exceptions in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer» CORRECT ANSWER is (b) outside the regular CODE

The explanation: Exception are handled outside the regular code.
73.

How many runtime error messages associated with exception?(a) 2(b) 4(c) 5(d) infiniteThis question was posed to me in homework.My question comes from Grouping of Exceptions topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right ANSWER is (b) 4

For explanation: There are four runtime error MESSAGES ASSOCIATED with exceptions. They are overflow_error, range_error, system_error and underflow_error.

74.

How to handle error in the destructor?(a) throwing(b) terminate(c) both throwing & terminate(d) tryThis question was addressed to me in a national level competition.My question comes from Exceptions That Are Not Errors topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer» CORRECT answer is (b) TERMINATE

Best explanation: It will not THROW an exception from the destructor but it will the PROCESS by USING terminate() function.
75.

What are the operators available in C++ for dynamic allocation and de-allocation of memories?(a) new(b) delete(c) compare(d) both new & deleteI have been asked this question in an internship interview.My enquiry is from Resource Management topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right CHOICE is (d) both new & delete

Easy explanation - new and delete operators are MAINLY used to allocate and deallocate during RUNTIME.

76.

Which is also called as abstract class?(a) virtual function(b) pure virtual function(c) derived class(d) base classI got this question in an online interview.The doubt is from Abstract Classes in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct option is (b) pure virtual function

The explanation: CLASSES that contain at least one pure virtual function are CALLED as ABSTRACT BASE classes.

77.

Which of the following is best to include under try block?(a) static values(b) const values(c) dynamic allocations(d) default valuesThis question was addressed to me during an interview.This is a very interesting question from Standard Exceptions topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The correct OPTION is (c) dynamic allocations

To explain I WOULD say: Because the dynamic allocations can change at any TIME, So it is best to include in try block.

78.

What are the different types of exceptions?(a) 1(b) 2(c) 3(d) 4I had been asked this question in exam.I'm obligated to ask this question of Exception Handling in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The correct answer is (B) 2

Explanation: There are two TYPES of exceptions: Synchronous and asynchronous exceptions. Synchronous exceptions that are caused by the event which can be controlled by the program WHEREAS Asynchronous exceptions are those which are BEYOND the control of the program.

79.

What is the difference between error and exception?(a) Both are the same(b) Errors can be handled at the run-time but the exceptions cannot(c) Exceptions can be handled at the run-time but the errors cannot(d) Both can be handled during run-timeI have been asked this question in an interview for internship.I would like to ask this question from Exception Handling in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT choice is (C) Exceptions can be handled at the run-time but the ERRORS cannot

The best I can explain: Exceptions can be handled during run-time whereas errors cannot be because exceptions occur DUE to some unexpected CONDITIONS during run-time whereas about errors compiler is sure and tells about them during compile-time.

80.

In how many categories, containers are divided?(a) 1(b) 2(c) 3(d) 4The question was posed to me in semester exam.Enquiry is from Standard Template Library in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer» RIGHT option is (d) 4

The best I can explain: Containers are divided into 4 categories NAMELY Sequence Containers, Associative Containers, UNORDERED Associative Containers and Container ADAPTORS.
81.

What is meant by template specialization?(a) It will have certain data types to be fixed(b) It will make certain data types to be dynamic(c) Certain data types are invalid(d) It will make all data types to be dynamicI have been asked this question during an interview for a job.This is a very interesting question from Specialization topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT CHOICE is (a) It will have certain data TYPES to be fixed

Best explanation: In the template specialization, it will make the template to be SPECIFIC for some data types.

82.

How many constructors can present in a class?(a) 1(b) 2(c) 3(d) multipleThe question was posed to me in exam.My question is from Class Hierarchies and Abstract Classes topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT answer is (d) multiple

For EXPLANATION: There can be multiple constructors of the same class, provided they have DIFFERENT SIGNATURES.

83.

What is meant by polymorphism?(a) class having many forms(b) class having only single form(c) class having two forms(d) class having four formsThe question was posed to me in an online interview.My doubt stems from Class Hierarchies and Abstract Classes topic in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The CORRECT ANSWER is (a) CLASS having many forms

Easiest explanation - POLYMORPHISM is LITERALLY meant class having many forms.

84.

Which keyword is used to throw an exception?(a) try(b) throw(c) throws(d) exceptI had been asked this question at a job interview.My query is from Exception Handling topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer» CORRECT OPTION is (B) throw

The best I can explain: ‘throw’ keyword is USED to throw exceptions if SOMETHING bad happens.
85.

How many Container Adaptors are provided by C++?(a) 2(b) 3(c) 4(d) 5This question was posed to me by my college professor while I was bunking the class.This question is from Standard Template Library topic in division Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right option is (b) 3

For explanation: C++ provides 3 types of Container Adaptors NAMELY Stack, Queue and Priority Queues.

86.

What are the Associative Containers?(a) Containers that implements data structures which can be accessed sequentially(b) Containers that implements sorted data structures for fast search in O(logn)(c) Containers that implements unsorted(hashed) data structures for quick search in O(1)(d) Containers that implements data structures which can be accessed non-sequentiallyThe question was posed to me in an internship interview.I need to ask this question from Standard Template Library topic in chapter Derived Classes, Templates & Exception Handling in C++ of C++

Answer» CORRECT answer is (B) Containers that implements SORTED data structures for FAST search in O(LOGN)

Explanation: Associative Containers is the subset of Containers that implements sorted data structures for fast search in O(logn).
87.

What does inheritance allow you to do?(a) create a class(b) create a hierarchy of classes(c) access methods(d) create a methodThe question was asked in semester exam.Query is from Design of Class Hierarchies in portion Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

The correct CHOICE is (b) CREATE a hierarchy of CLASSES

For explanation: Inheritance HELPS in creating hierarchy of classes by making connections between different classes in which one is called base class and other is class derived class.

88.

What are the containers?(a) Containers store objects and data(b) Containers stores all the algorithms(c) Containers contain overloaded functions(d) Containers contain set of IteratorsThis question was posed to me in final exam.This interesting question is from Standard Template Library in section Derived Classes, Templates & Exception Handling in C++ of C++

Answer» RIGHT OPTION is (a) Containers STORE objects and data

To explain I would SAY: Containers is a component of STL which stores objects and data.
89.

Pick the correct statement.(a) STL is a generalized library(b) Components of STL are parameterized(c) STL uses the concept of templates classes and functions to achieve generalized implementation(d) All of the mentionedThis question was posed to me during an internship interview.The above asked question is from Standard Template Library in division Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct OPTION is (d) All of the mentioned

Explanation: STL is a generalized library and COMPONENTS of STL are PARAMETERIZED. STL uses the concept of templates classes and function to ACHIEVE generalized implementation.

90.

How many types of inheritance are there in c++?(a) 2(b) 3(c) 4(d) 5I have been asked this question in exam.The origin of the question is Class Hierarchies and Abstract Classes in division Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Correct option is (d) 5

The best I can explain: There are FIVE types of inheritance in C++. They are SINGLE, Multiple, HIERARCHICAL, MULTILEVEL, Hybrid.

91.

How many types of class are there in c++?(a) 1(b) 2(c) 3(d) 4The question was asked by my school principal while I was bunking the class.The doubt is from Design of Class Hierarchies in division Derived Classes, Templates & Exception Handling in C++ of C++

Answer»

Right option is (c) 3

Easiest EXPLANATION - There are three TYPES of classes. They are abstract BASE classes, concrete DERIVED classes, STANDALONE classes.