0% found this document useful (0 votes)
3K views43 pages

Oop Mcqs Unit IV

The document contains 31 multiple choice questions related to C++ templates, exceptions, and exception handling. Some key topics covered include: - The purpose of template parameters - Syntax for class and function templates - Scope of template parameters - Advantages of exception handling like removing error handling code from main logic - What types of errors typically cause exceptions - How exceptions propagate through the call stack - Constructors and destructors being called when exceptions are thrown

Uploaded by

Tejas Randive
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)
3K views43 pages

Oop Mcqs Unit IV

The document contains 31 multiple choice questions related to C++ templates, exceptions, and exception handling. Some key topics covered include: - The purpose of template parameters - Syntax for class and function templates - Scope of template parameters - Advantages of exception handling like removing error handling code from main logic - What types of errors typically cause exceptions - How exceptions propagate through the call stack - Constructors and destructors being called when exceptions are thrown

Uploaded by

Tejas Randive
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/ 43

Id 1

Question What is meaning of template parameter?


A It is used to pass a type as argument
B Used to evaluate a type
C It can of no return type
D None of the mentioned
Answer A
Marks 1
Unit IV

Id 2
Question ______Keyword is used in template.
A Class
B Typename
C Both a and b
D Using
Answer C
Marks 1
Unit IV

Id 3
Question What is scope of template parameter?
A Inside a block only
B Inside the class only
C Throughout program
D All of the above
Answer A
Marks 1
Unit IV

Id 4
Question Function overloading is also similar to which of the following
A Operator overloading
B Destructor overloading
C Constructor overloading
D Virtual function
Answer B
Marks 1
Unit IV

Id 5
Question Generic programming is approach of______________________which are applicable for
all types
A Generalised algorithm
B Pseude algorithm
C Both a and b
D None of the above
Answer A
Marks 1
Unit IV

Id 6
Question Template are of types
A Function template
B Class template
C Both a and b
D None of the above
Answer C
Marks 1
Unit IV

Id 7
Question Class template can be created using________syntax.
A Template<class T>class classname
B Template<class T1,class T2> class classname
C Both a and b
D None of the above mentioned
Answer C
Marks 1
Unit IV

Id 8
Question Syntax for creating a function template is
A Template<typename t>returntype function name
B Template<class T> returntype function name
C Both a and b
D None of the above mentioned
Answer C
Marks 1
Unit IV

Id 9
Question Pick up the correct statement
i)template allow us to define generic classes and functions
ii)template support generic programming
iii)function template overloading is possible
A i only
B i and ii only
C ii and iii only
D i, ii and iii
Answer D
Marks 1
Unit IV

Id 10
Question Template function can be overloaded
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 11
Question Why we use :: template-template parameter?
A binding
B rebinding
C both a &b
D none of these
Answer C
Marks 1
Unit IV

Id 12
Question Which of the things does not require instantiation?
A functions
B non virtual member function
C member class
D all of the mentioned
Answer D
Marks 1
Unit IV

Id 13
Question A template provides a convenient way to make a family of
A variables.
B functions
C classes
D B and C
Answer D
Marks 1
Unit IV

Id 14
Question Templates automatically create different versions of a function, depending on user input.
A TRUE
B FALSE
C
D
Answer B
Marks 1
Unit IV

Id 15
Question A template class
A is designed to be stored in different containers.
B works with different data types.
C generates objects which must all be identical.
D generates classes with different numbers of member functions.
Answer B
Marks 1
Unit IV

Id 16
Question There can be more than one template argument.
A TRUE
B FALSE
C
D
Answer A
Marks 1
Unit IV

Id 17
Question Actual code for a template function is generated when
A the function declaration appears in the source code.
B the function definition appears in the source code.
C a call to the function appears in the source code.
D the function is executed at runtime.
Answer C
Marks 1
Unit IV

Id 18
Question An exception is typically caused by
A the programmer who writes an application’s code.
B the creator of a class who writes the class member functions.
C a runtime error.
D an operating system malfunction that terminates the program.
Answer C
Marks 1
Unit IV
Id 19
Question Statements that might cause an exception must be part of a catch block.
A TRUE
B FALSE
C
D
Answer B
Marks 1
Unit IV

Id 20
Question Exceptions are thrown
A from the catch block to the try block.
B from a throw statement to the try block.
C from the point of the error to a catch block.
D from a throw statement to a catch block.
Answer D
Marks 1
Unit IV

Id 21
Question A statement that throws an exception does not need to be located in a try block.
A TRUE
B FALSE
C
D
Answer B
Marks 1
Unit IV

Id 22
Question The following is/are errors for which an exception would typically be thrown:
A An excessive amount of data threatens to overflow an array.
B new cannot obtain the requested memory.
C A power failure shuts down the system.
D A and B
Answer D
Marks 1
Unit IV

Id 23
Question Additional information sent when an exception is thrown may be placed in
A the throw keyword.
B the function that caused the error.
C the catch block.
D an object of the exception class.
Answer D
Marks 1
Unit IV

Id 24
Question A program can continue to operate after an exception has occurred.
A TRUE
B FALSE
C
D
Answer A
Marks 1
Unit IV

Id 25
Question What is the output of following program?

#include <iostream>
using namespace std;
int main()
{
int x = -1;
try {
cout <<"Inside try \n";
if (x <0)
{
throw x;
cout <<"After throw \n";
}
}
catch (int x ) {
cout <<"Exception Caught \n";
}

cout <<"After catch \n";


return 0;
}
A Inside try
Exception Caught
After throw
After catch
B Inside try
Exception Caught
After catch
C Inside try
Exception Caught
D Inside try
After throw
After catch
Answer B
Marks 2
Unit IV

Id 26
Question What is the advantage of exception handling?
1) Remove error-handling code from the software's main line of code.
2) A method writer can chose to handle certain exceptions and delegate others to the
caller.
3) An exception that occurs in a function can be handled anywhere in the function call
stack.
A Only 1
B 1, 2 and 3
C 1 and 3
D 1 and 2
Answer B
Marks 2
Unit IV

Id 27
Question What should be put in a try block?
1. Statements that might cause exceptions
2. Statements that should be skipped in case of an exception
A Only 1
B Only 2
C Both 1 and 2
D None of the above
Answer C
Marks 1
Unit IV

Id 28
Question What is the output of following program

#include<iostream>
using namespace std;

class Base {};


class Derived: public Base {};
int main()
{
Derived d;
try {
throw d;
}
catch(Base b) {
cout<<"Caught Base Exception";
}
catch(Derived d) {
cout<<"Caught Derived Exception";
}
return 0;
}
A Caught Derived Exception
B Caught Base Exception
C Caught Derived Exception
Caught Base Exception
D Compiler Error
Answer B
Marks 1
Unit IV

Id 29
Question What is the output of following program?

#include <iostream>
using namespace std;

int main()
{
try
{
throw 10;
}
catch (...)
{
cout <<"default exception\n";
}
catch (int param)
{
cout <<"int exception\n";
}

return 0;
}
A default exception
B int exception
C default exception
int exception
D Compiler Error
Answer D
Marks 1
Unit IV

Id 30
Question What is the output of following program?

#include <iostream>
using namespace std;

class Test {
public:
Test() { cout <<"Constructing an object of Test "<<endl; }
~Test() { cout <<"Destructing an object of Test " <<endl; }
};

int main() {
try {
Test t1;
throw 10;
} catch(int i) {
cout <<"Caught "<<i <<endl;
}
}
A Caught 10
B Constructing an object of Test
Caught 10
C Constructing an object of Test
Destructing an object of Test
Caught 10
D Compiler Errror
Answer C
Marks 2
Unit IV

Id 31
Question What happens in C++ when an exception is thrown and not caught anywhere like
following program?

#include <iostream>
using namespace std;

int fun() throw (int)


{
throw 10;
}

int main() {
fun();
return 0;
}
A Compiler error
B Abnormal program termination
C Program doesn't print anything and terminates normally
D None of the above
Answer B
Marks 1
Unit IV

Id 32
Question Which alternative can replace the throw statement ?
A Exit
B For
C Break
D Return
Answer D
Marks 1
Unit IV

Id 33
Question Which of the following keyword can not be appered inside the class?
A Virtual
B Static
C Template
D Friend
Answer C
Marks 1
Unit IV

Id 34
Question What is template?
A Template is formula for creating a generic class
B Template is used to manipulate class
C Template is used for creating functions
D None of these
Answer A
Marks 1
Unit IV

Id 35
Question Select the correct syntax of template:
A Template
B Template<>
C Temp
D None of these
Answer B
Marks 1
Unit IV

Id 36
Question A class is generated from template class is called _______.
A inherited class
B derived class
C generated class
D subclass
Answer C
Marks 1
Unit II

Id 37
Question ________ is useful when template of template is used?
A Friend function
B Static function
C Typedef
D Inheritance
Answer C
Marks 1
Unit IV

Id 38
Question Which of the C++ feature allows you to create classes that are dynamic for using data
types?
A Templates
B Inheritance
C Polymorphism
D Information hiding
Answer A
Marks 1
Unit IV

Id 39
Question A function template means _______.
A creating a function having exact type
B creating a function without having to specify exact type
C both a and b
D none of these
Answer B
Marks 1
Unit IV

Id 40
Question Which of the following is used to describe the function using placeholder type?
A Template type parameter
B Template parameter
C Template type
D None of these
Answer A
Marks 1
Unit IV

Id 41
Question String template is used _____.
A to replace a string.
B to replace a string with another string
C to delete a string
D none of these
Answer B
Marks 1
Unit IV

Id 42
Question Maximum number of template argument in function template is _______.
A two
B three
C four
D many
Answer D
Marks 1
Unit IV

Id 43
Question Template function must have
A one or more than one argument
B zero argument
C only one argument
D at least two arguments
Answer A
Marks 1
Unit IV

Id 44
Question Template function must have at least ________ generic data type.
A zero
B one
C two
D none of these
Answer B
Marks 1
Unit IV

Id 45
Question Templates provide way of abstracting ______ information.
A type
B data
C method
D access
Answer A
Marks 1
Unit IV

Id 46
Question If you create instantiation of a class template with an int and then create a second
instantiation with a double then
A once the function is used for one data type it becomes unavailable for other type
B you can not perform this kind of operation in C++
C you must precede each function call with the word int or double
D none of these
Answer C
Marks 1
Unit IV

Id 47
Question If templates were removed from C++,Which of the following will be true?
I. Some algorithms could no longer be implemented
II. Any particular algorithms could still be implemented but often less elegantly.
A Only I is true
B Only II is true
C Both I and II is true
D None of these
Answer D
Marks 1
Unit 4

Id 48
Question In the template <class T>declaration of T stands for ________.
A integer data type
B arbitary class
C generic data types
D none of these
Answer C
Marks 1
Unit IV

Id 49
Question What is the meaning of template parameter?
A It is used to pass a type as argument
B It is used to evalute a type
C It has no return type
D None of these
Answer A
Marks 1
Unit IV

Id 50
Question What can be passed by non-type template parameter during compile time?
A Int
B Double
C Char
D constant expression
Answer D
Marks 1
Unit IV

Id 51
Question Choose the correct statement from the following:
A Template function will take long time to execute
B Template functions are written when you want to have only one code for many different
types
C due to template function the duplicate code will get increased
D None of these
Answer B
Marks 1
Unit IV

Id 52
Question How many types of templates are there in c++?
A Two
B Three
C Four
D None Of These
Answer A
Marks 1
Unit IV
Id 53
Question What is the task of compiler while handling template?
A type association
B Portability
C code elimination
D all of the above
Answer C
Marks 1
Unit IV

Id 54
Question What should be the name of the parameter that the template should take?
A same as class
B same as function
C same as template
D none of these
Answer C
Marks 1
Unit IV

Id 55
Question Which keyword can be used with template?
A Typename
B operator
C both a and b
D None of these
Answer A
Marks 1
Unit IV

Id 56
Question Which of the following describes a difference between template function and
template class in c++?
A The compiler determines the type of a template function's arguments, but
the types of template classes must be stated explicitly when declaring objects
B template functions cannot be defined for user-defined types, but template classes can
C template classes cannot be defined for user-defined types,but
templatefunctions can.
D None Of These
Answer A
Marks 1
Unit IV

Id 57
Question What is the validity of templet parameter?
A Inside the class
B Inside the block
C whole program
D None of these
Answer B
Marks 1
Unit IV

Id 58
Question Which of the following does not required installation ?
A Non virtual member function
B Member class
C Function
D All of above
Answer D
Marks 1
Unit IV

Id 59
Question Which keyword is used to handle the exception ?
A Try
B Catch
C Throw
D Exception
Answer B
Marks 1
Unit IV

Id 60
Question What is the use of the keyword finally ?
A It is used at the start of the program for handling all the exceptions
B It is used at the end of the program to handle all the exceptions
C It can be used anywhere in the program to handle all the exceptions
D None of these
Answer B
Marks 1
Unit IV

Id 61
Question Which of the following most preferred way of throwing and handling exception?
A Throw by value and catch by reference
B Throw by reference and catch by value
C Throw by value and catch by value
D None of these
Answer A
Marks 1
Unit IV
Id 62
Question Which of the following is the most general exception handler that catches exception of
any type?
A Catch(std::exception)
B Catch(std:any_exception)
C Catch(...)
D Catch()
Answer C
Marks 1
Unit IV

Id 63
Question Which of the following causes an exception
A Missing parenthesis in main()
B Calling a function which is not present
C A syntax error
D a run time error
Answer D
Marks 1
Unit IV

Id 64
Question Which block should be placed after try block ?
A Throw
B Catch
C both a or b
D none of these
Answer C
Marks 1
Unit IV

Id 65
Question Choose the correct statement
A Exception are not suitable for critical points in the program
B Exception are suitable for critical points in the program
C Both a&b
D None of these
Answer A
Marks 1
Unit IV

Id 66
Question In C++ program handling, a try block must be followed by _____catch blocks
A exactly one
B one or more
C exactly two
D none of these
Answer B
Marks 1
Unit IV

Id 67
Question The process of handling the actual exception occurs _________
A inside the program
B outside the program
C both a &b
D none of these
Answer B
Marks 1
Unit IV

Id 68
Question Which of the following is used to check the error in the block?
A Try
B Throw
C Catch
D None of these
Answer A
Marks 1
Unit IV

Id 69
Question What should be present when throwing object ?
A Constructor
B Destructor
C copy constructor
D none of these
Answer C
Marks 1
Unit IV

Id 70
Question For handling the exception in C++ _______ are used
A catch handlers
B exception handlers
C Pointers
D none of these
Answer B
Marks 1
Unit IV

Id 71
Question For handling the exceptions in C++ _________ is used .
A handler function
B terminate function
C both a &b
D none of these
Answer B
Marks 1
Unit IV

Id 72
Question How many parameters does the throw expression can have ?
A 0
B 1
C 2
D 3
Answer B
Marks 1
Unit IV

Id 73
Question What kind of exceptions are used in C++
A Handled
B Unhandled
C Static
D Dynamic
Answer B
Marks 1
Unit IV

Id 74
Question What will happen when exception is uncaught?
A Arise an error
B program will run
C execute in a loop
D none of these
Answer A
Marks 1
Unit IV

Id 75
Question Choose the correct statement
A A function can throw any type of exception
B a function can throw an exception of certain type only
C A exception can't throw any type of exception
D none of these
Answer B
Marks 1
Unit 4

Id 76
Question What fuunction will be called when we have uncaught exception?
A Catch
B Throw
C Terminate
D none of these
Answer C
Marks 1
Unit IV

Id 77
Question What will happen when a programs throws any other of exception other than specified ?
A still execute
B Terminate
C raise an error
D none of these.
Answer C
Marks 1
Unit IV

Id 78
Question Which statement is used to catch all types of exceptions?
A catch()
B catch(Test t)
C catch
D none of these
Answer D
Marks 1
Unit IV

Id 79
Question Which keyword can be used as a template
A Exception
B Typename
C both a & b
D Function
Answer B
Marks 1
Unit IV
Id 80
Question An Exception is thrown using _____________keyword in cpp
A Throws
B Throw
C Threw
D Thrown
Answer B
Marks 1
Unit IV

Id 81
Question Which parameter is legal for non-type template?
A pointer to member
B object
C class
D none of these
Answer A
Marks 1
Unit IV

Id 82
Question Which of the things does not require instantiation?
A functions
B Non virtual member function
C member class
D all of these
Answer D
Marks 1
Unit IV

Id 83
Question Which of the following permits function overloading on c++?
A Data Type
B Number of arguments
C A &B both
D none of these
Answer C
Marks 1
Unit IV

Id 84
Question Function overloading is also similar to which of the following?
A Operator Overloading
B Constructer overloading
C Destructor overloading
D none of the above
Answer B
Marks 1
Unit IV

Id 85
Question Which is dependent on template parameter
A base class
B abstract class
C method
D none of the above
Answer A
Marks 1
Unit IV

Id 87
Question How to declare a template?
A Tem
B Temp
C Template<>
D none of these
Answer C
Marks 1
Unit IV

Id 88
Question What may be the name of parameter that the template should take?
A same as template
B same as class
C same as function
D none of these
Answer A
Marks 1
Unit IV

Id 89
Question Which is used to handle the exceptions in c++?
A catch handler
B handler
C exception handler
D all of these
Answer B
Marks 1
Unit IV

Id 90
Question Which is called on allocating the memory for array of objects?
A Function
B Method
C Destructor
D Constructor
Answer D
Marks 1
Unit IV

Id 91
Question Which value is placed in the base class?
A Inherited value
B Derived value
C Default type values
D Both a and b
Answer C
Marks IV
Unit IV

Id 92
Question Which is used to get the input during runtime?
A cout
B cin
C Template
D All of the above
Answer B
Marks 1
Unit IV

Id 93
Question __________is used to perform the generic programming.
A Class
B Template
C Function
D Inheritance
Answer All of the above
Marks B
Unit IV

Id 94
Question A template can be considered as a kind of macros
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 95
Question We can not define more than 2 placeholder in class/function template.
A False
B True
C
D
Answer A
Marks 1
Unit IV

Id 96
Question When template is defined with parameter that would be replaced by specified _______at
the time of actual use of class or function.
A Keyword
B Operator
C Datatype
D None of the above mentioned
Answer C
Marks IV
Unit IV

Id 97
Question Templates sometimes called as ___________
A Parameterized classes
B Parameterized function
C Both a and b
D None of the above mentioned
Answer C
Marks 1
Unit IV

Id 98
Question Exceptions are of type
A Synchronous
B Asynchronous
C Both a and b
D None of the above mentioned
Answer C
Marks 1
Unit IV

Id 99
Question “out-of-range”, “overflow” are the type of exceptions
A Asynchronous
B Synchronous
C Default
D None of the above
Answer B
Marks 1
Unit IV

Id 100
Question The most type of error--------.
A Logical error
B Syntactic error
C Both a and b
D Class
Answer C
Marks 1
Unit IV

Id 101
Question Run time error is known as ______
A Logical error
B Syntactic error
C Exception
D All of the above mentioned
Answer C
Marks 1
Unit IV

Id 102
Question How the exception is throw
A throw exception
B throw(exception)
C throw
D All of the above
Answer D
Marks 1
Unit IV

Id 103
Question Can we throw exception more than one time
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 104
Question Which statement we have to use rethrowing exception
A throw(exception)
B Throw
C Both a and b
D None of the above mentioned
Answer B
Marks 1
Unit IV

Id 105
Question Exception can be handle if_______
A Throwing argument is match with catch block
B Throwing argument is not match with catch block
C Exception is not thrown
D None of the abve
Answer A
Marks 1
Unit IV

Id 106
Question With this concept same algorithm can be used for different data types
A Procedure oriented paradigm
B Generic programming
C Both a and b
D None of the above
Answer B
Marks 1
Unit IV

Id 106
Question Template is a way creating generalize functions and classes which are applicable for all
data types
A False
B True
C
D
Answer B
Marks 1
Unit IV

Id 107
Question Class template is applicable for ___.
A For function only
B For that class only
C Both a and b
D None of the above mentioned
Answer B
Marks 1
Unit IV

Id 108
Question Function template is applicable for_________.
A For function only
B For that class only
C Both a and b
D None of the above mentioned
Answer A
Marks 1
Unit IV

Id 109
Question How many kinds of parameters are there in c++
A 1
B 2
C 3
D 4
Answer C
Marks 1
Unit IV

Id 110
Question Which type of program is recommended to include in try block
A Static memory allocation
B Dynamic memory allocation
C Const reference
D Pointer
Answer B
Marks 1
Unit IV

Id 111
Question How to handle error in destructor
A Throwing
B Terminate
C Both a and b
D None of the mentioned
Answer B
Marks 1
Unit IV
Id 112
Question In catch statement we have multiple parameters
A Yes
B No
C
D
Answer B
Marks 1
Unit IV

Id 113
Question ------kind of exceptions are in c++.
A Handled
B Static
C Both a and b
D Unhandled
Answer A
Marks 1
Unit IV

Id 114
Question Pick up the correct statement
A To throw exception we have to use catch statement
B Error occurring code is placed in try block
C We can not have multiple throwing mechanism in c++
D Both and b
Answer B
Marks 1
Unit IV

Id 115
Question Can we used constructor for exception handling
A Yes
B No
C
D
Answer A
Marks 1
Unit IV

Id 116
Question Class template can be overloaded
A True
B False
C
D
Answer B
Marks 1
Unit IV

Id 117
Question ______is a generic class handler
A Catch(---)
B Catch(-,-)
C Catch(…)
D Catch(void)
Answer C
Marks 1
Unit IV

Id 118
Question If the exception is not handled then which standard library function get invoked
A stop()
B terminate()
C Read()
D Write()
Answer B
Marks 1
Unit IV

Id 119
Question Exception can be only built in type
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 120
Question What will be output of program
#include<iostream>
using namespace std;
template<class T>
T display(T x)
{
cout<< “using template x=”<<x<<“\n”;
}
int display(int x)
{
cout<<“Normal display x=”<<x <<“\n”;
}
int main()
{
display(2.3);
display(3);
diplay(1.1);
}
A Normal display x=2.3
Using template x=3
Normal display x=1.1
B using template x=2.3
Normal display x=3
using template x=1.1
C using template x=3
Normal display x=2.3
using template x=1.1
D None of the above
Answer B
Marks 2
Unit IV

Id 121
Question 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
C
D
Answer B
Marks 1
Unit IV

Id 122
Question Can we write try block within try block
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 123
Question Can we prevent a function from throwing any exceptions
A Yes
B No
C
D
Answer A
Marks 1
Unit IV

Id 124
Question What is return type of uncaught_exception() is----
A Char*
B Double
C Int
D Bool
Answer D
Marks 1
Unit IV

Id 125
Question Can we write a throw statement inside catch statement
A Yes
B No
C
D
Answer A
Marks 1
Unit IV

Id 126
Question We can define our own exceptions in c++
A False
B True
C
D
Answer B
Marks 1
Unit IV

Id 127
Question Stack unwinding deals with
A Polymorphism
B inheritance
C Exception handling
D Classes
Answer C
Marks 1
Unit IV
Id 128
Question What is STL
A Standard Term Library
B Standard Tree Library
C Standard Template Library
D None of the above mentioned
Answer C
Marks 1
Unit IV

Id 129
Question Pick up the correct statement
• Catch statement be placed immediately after try block
• It can have multiple parameters
• There must be multiple catch handler for a try block
• Generic catch statement we can placed anywhere in program
A i and ii
B i and iii
C i and iv
D i , ii and iii
Answer B
Marks 2
Unit IV

Id 130
Question Generic catch should be placed at
A End of all statement
B Before try
C Before throw
D Inside try
Answer A
Marks 1
Unit IV

Id 131
Question Irrespective of exception occurrence, catch handler will be always executed
A Yes
B No
C
D
Answer B
Marks 1
Unit IV

Id 132
Question From where does the template class can derived
A Regular non-templated c++ class
B Templated class
C Both a and b
D None of the above mentioned
Answer C
Marks 2
Unit IV

Id 133
Question What is done by compiler for templates
A Type-safe
B Code elimination
C Portability
D All of the above mentioned
Answer A
Marks 2
Unit IV

Id 134
Question Catch handler itself may detect and throw an exception
A True
B False
C
D
Answer A
Marks 1
Unit Iv

Id 135
Question If the thrown exception will not be caught by any catch statement then it will be passed to
next outer try/catch sequence for processing.
A False
B True
C
D
Answer B
Marks 1
Unit IV

Id 136
Question While specifying the exceptions, the type-list specifies the________ that may be thrown.
A How many exceptions
B Type of exception
C Both a and b
D None of the above mentioned
Answer B
Marks 2
Unit IV

Id 137
Question When an exception is rethrown ,it will not be caught by the__________or other catch in
that group.
A Same catch
B Nested catch
C Both a and b
D None of the above mentioned
Answer A
Marks 2
Unit IV

Id 138
Question Try block can throw any exception
A True
B False
C
D
Answer B
Marks 1
Unit IV

Id 139
Question Pick up the correct statement from the following
• Multiple catch statement are there in c++.
• We have generic catch statement to handle all type of exception
• Try block is used to throw and exception

A i and iii
B i
C ii
D i and ii only
Answer D
Marks 2
Unit IV

Id 140
Question When an exception is not caught
A Program is go in wait condition
B Program is aborted
C Program works fine way
D None of the above mentioned
Answer B
Marks 1
Unit IV

Id 141
Question We can place two or more catch blocks together to catch and handle multiple types of
exceptions thrown by a try blocks
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 142
Question It is also possible to make a catch statement to catch all types of exceptions using ellipses
as its arguments
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 143
Question We can restrict a function to throw only a set of specified exceptions by adding a throw
specification clause to the function definition.
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 144
Question We may also use non-type parameters such basic or derived data types as arguments
template
A True
B False
C
D
Answer A
Marks 1
Unit IV
Id 145
Question Pick up the correct statement from the following related with overloading of template
functions
• Call an ordinary function that has an exact match
• Call a template function that could be created with an exact macth
• Try normal overloading resolution to ordinary functions and call the one
that matches
A 1 and 2 only
B 2 and 3 only
C All of the above
D None of the above mentioned
Answer C
Marks 2
Unit IV

Id 146
Question What will be output of the a following program
#include<iostream>
using namespace std;
template <class T>
void display(T x)
{
cout<<“Template display:”<<x<< “\n”;
}
void display(int x)
{
cout<<“Explicit display:”<<x <<“\n”;
}
int main()
{
display(100);
display(12.34);
display(‘c’);
}
A Template display:100
Template display:12.34
Template display: c
B Explicit display:100
Template display:12.34
Template display: c
C Explicit display:100
Template display:12.34
Explicit display: c
D Template display:100
Template display:12.34
Template display: c
Answer B
Marks 2
Unit IV

Id 147
Question What will be output of program
#include <iostream>
using namespace std;
int main()
{
cout <<"Start\n";
try {
cout <<"Inside try block\n";
throw 100;
cout << "This will not execute";
}
catch (int i) {
cout <<"Caught an exception -- value is: ";
cout <<i <<"\n";
}
cout <<"End";
return 0;
}
A Start
Inside try block
Caught an exception -- value is: 100
End
B Start
End
C Start
Inside try block
End
D None of the above mentioned
Answer A
Marks 2
Unit IV

Id 148
Question What will be output of following program
#include <iostream>
using namespace std;
void Xhandler(int test)
{
try{
if(test) throw test;
else throw "Value is zero";
}
catch(int i) {
cout << "Caught Exception #: " <<i <<'\n';
}
catch(const char *str) {
cout <<"Caught a string: ";
cout << str <<'\n';
}
}
int main()
{
cout <<"Start\n";
Xhandler(1);
Xhandler(2);
Xhandler(0);
Xhandler(3);
cout << "End";
return 0;
}
A Start
Caught Exception #: 1
Caught Exception #: 2
Caught Exception #: 0
Caught Exception #: 3
End
B Start
Caught Exception #: 1
Caught Exception #: 2
Caught a string: 0
Caught Exception #: 3
End
C Start
Caught Exception #: 1
Caught Exception #: 2
Caught a string: Value is zero
Caught Exception #: 3
End
D None of the mentioned
Answer C
Marks 2
Unit IV

Id 149
Question What will be output of program
#include <iostream>
using namespace std;
void Xhandler(int test)
{
try{
if(test==0) throw test; // throw int
if(test==1) throw 'a'; // throw char
if(test==2) throw 123.23; // throw double
}
catch(int i) { // catch an int exception
cout <<"Caught an integer\n";
}
catch(...) { // catch all other exceptions
cout <<"Caught One!\n";
}
}
int main()
{
cout <<"Start\n";
Xhandler(0);
Xhandler(1);
Xhandler(2);
cout <<"End";
return 0;
}
A Start
Caught One!
Caught One!
Caught One!
End
B
C Start
Caught an integer
Caught One!
Caught One!
End
D Start
Caught One!
Caught an integer
Caught One!
End
Answer C
Marks 2
Unit None of the above mentioned

Id 150
Question What will be output of following program
#include <iostream>
using namespace std;
template <class Type1, class Type2> class myclass
{
Type1 i;
Type2 j;
public:
myclass(Type1 a, Type2 b) { i = a; j = b; }
void show() { cout <<i << ' ' <<j <<'\n'; }
};
int main()
{
myclass<int, double>ob1(10, 0.23);
myclass<char, char *>ob2('X', "Templates add power.");
ob1.show(); // show int, double
ob2.show(); // show char, char *
return 0;
}
A 10 0.23
X Templates add power.
B 0.23 10
X Template add power
C 10 10
X template add power
D Compilation error
Answer A
Marks 2
Unit IV

Id 151
Question We can combine operator overloading with a class
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 152
Question If you overload a generic function, that overloaded function overrides (or "hides") the
generic function relative to that specific version.
A True
B False
C
D
Answer A
Marks 1
Unit IV

Id 153
Question What will be output of following programming
#include <iostream>
using namespace std;
template <class T>
T GetMax (T a, T b) {
T result;
result = (a>b)? a : b;
return (result);
}
int main () {
int i=5, j=6, k;
long l=10, m=5, n;
k=GetMax<int>(i,j);
n=GetMax<long>(l,m);
cout <<k << endl;
cout <<n <<endl;
return 0;
}
A 6
10
B 5
5
C 10
10
D Compilation error
Answer A
Marks 2
Unit IV

Id 154
Question What will be output of following program
#include <iostream>
using namespace std;
template <class T>
class mypair {
T a, b;
public:
mypair (T first, T second)
{a=first; b=second;}
T getmax ();
};
template <class T>
T mypair<T>::getmax ()
{
T retval;
retval = a>b? a : b;
return retval;
}
int main () {
mypair <int>myobject (100, 75);
cout << myobject.getmax();
return 0;
}
A 75
B 100
C 75
100
D Compilation error
Answer B
Marks 2
Unit IV

Id 155
Question What will be output of following program
#include <iostream>
#include <exception>
using namespace std;
class myexception: public exception
{
virtual const char* what() const throw()
{
return "My exception happened";
}
} myex;
int main () {
try
{
throw myex;
}
catch (exception&e)
{
cout << e.what() <<endl;
}
return 0;
}
A Exception happened
B My exception happened.
C Run Time error
D Compilation error
Answer B
Marks 2
Unit IV

Id 156
Question Pick up the correct statement from following
1.Exception handling is not supported c++
2.Template support generic programming in c++
3.overloading of function template is possible in c++
4.generic catch template can handle all types of exceptions
A 2 and 3 only
B 3 and 4 only
C 1, 2 and 3 only
D 2, 3 and 4 only
Answer D
Marks 2
Unit IV

You might also like