2.
Specialized templates work with a specific data type.
Explanation
Specialized templates are designed to work with a specific data type, meaning they are tailored to handle operations and manipulations specific to that particular type. This allows for more efficient and optimized code, as the template can be customized to meet the requirements of the specific data type it is designed for. Therefore, the statement "Specialized templates work with a specific data type" is true.
3.
Private members of a private base class become inaccessible to the derived class.
Explanation
Private members of a private base class become inaccessible to the derived class because private members are only accessible within the class they are declared in. Inheritance allows the derived class to inherit the members of the base class, but if those members are declared as private, they cannot be accessed or inherited by the derived class. This ensures that the derived class cannot directly access or modify the private members of the base class, maintaining encapsulation and data hiding.
4.
STL algorithms are implemented as function templates.
Explanation
STL algorithms are indeed implemented as function templates. This means that the algorithms are defined in a generic way, allowing them to work with different types of data. By using function templates, the algorithms can be applied to various containers without the need for rewriting the code for each specific container type. This makes the STL algorithms highly reusable and flexible.
5.
It isn't possible for a base class to have more than one constructor.
Explanation
A base class can have more than one constructor. This allows the derived classes to choose which constructor to call when creating an instance of the derived class. Having multiple constructors in a base class provides flexibility and allows for different initialization options.
6.
The __________ block handles an exception.
Correct Answer
catch
Explanation
The catch block handles an exception. In a try-catch statement, the catch block is executed if an exception is thrown within the corresponding try block. It allows the program to catch and handle the exception, preventing it from causing a runtime error and allowing for appropriate error handling or recovery actions to be taken.
7.
Data may be passed with an exception by storing it in members of an exception class.
Explanation
Data can be passed with an exception by storing it in members of an exception class. When an exception is thrown, the exception object can contain additional information about the error or the state of the program at the time of the exception. This additional data can be stored in the members of the exception class, allowing it to be accessed and used for debugging or error handling purposes. This approach can provide more context and information about the exception, making it easier to diagnose and resolve issues in the code.
8.
Only one generic type may be used with a template.
Explanation
The statement is false because templates in programming allow for multiple generic types to be used. Templates provide a way to define a generic class or function that can be used with different types, allowing for flexibility and reusability in code. By using templates, developers can write code that works with different types without having to rewrite the same logic multiple times.
9.
The base class's access specification affects the way the derived class inherits
members of the base class.
Explanation
The access specification of the base class determines the visibility and accessibility of its members in the derived class. If the base class's members are declared as public, they can be accessed by the derived class and its objects. If they are declared as protected, they can be accessed by the derived class and its objects, as well as by any other class that inherits from the derived class. If they are declared as private, they cannot be accessed by the derived class or any other class. Therefore, the access specification of the base class does affect the way the derived class inherits the members of the base class.
10.
Private members of a protected base class become inaccessible to the
derived class.
Explanation
In object-oriented programming, a protected base class allows its derived classes to access its members. However, private members of a protected base class are not accessible to the derived class. This means that the derived class cannot directly access or modify the private members of the protected base class. Therefore, the statement "Private members of a protected base class become inaccessible to the derived class" is true.
11.
The base class constructor is called after the derived class constructor.
Explanation
In object-oriented programming, the base class constructor is called before the derived class constructor. This is because when an object of the derived class is created, the base class constructor is responsible for initializing the inherited members before the derived class constructor can initialize its own members. Therefore, the statement that the base class constructor is called after the derived class constructor is incorrect.
12.
Pointers to a base class may be assigned the address of a derived class object.
Explanation
In object-oriented programming, a base class is a class that is inherited by other classes, called derived classes. Pointers are variables that store memory addresses. In C++, a pointer to a base class can be assigned the address of a derived class object because a derived class inherits all the members and methods of the base class. This allows for polymorphism, where a pointer to a base class can be used to access the members and methods of both the base class and any derived classes. Therefore, the statement is true.
13.
It is possible to overload two function templates.
Explanation
Function templates in C++ allow us to define generic functions that can work with different data types. Overloading refers to having multiple functions with the same name but different parameters. We can overload function templates by defining multiple function templates with the same name but different template parameters or function parameters. This allows us to have different implementations of the same function template depending on the types or number of arguments passed to it. Therefore, it is possible to overload two function templates.
14.
A class template may not be used as a base class.
Explanation
A class template can be used as a base class. In C++, a class template is a blueprint for generating classes, and it can be used as a base for deriving other classes. This allows for the creation of specialized classes that inherit the properties and behaviors defined in the template. Therefore, the statement "A class template may not be used as a base class" is false.
15.
When both a base class and a derived class have destructors, the base class's destructor is called ________ (first/last).
Correct Answer
last
Explanation
In object-oriented programming, when both a base class and a derived class have destructors, the base class's destructor is called last. This means that the derived class's destructor is called first, followed by the base class's destructor. This order allows for proper cleanup and deallocation of resources, as the derived class may depend on resources initialized in the base class. Therefore, it is important to call the base class's destructor after the derived class's destructor to ensure the correct order of cleanup operations.
16.
Protected members of a private base class become public members of the derived class.
Explanation
Protected members of a private base class do not become public members of the derived class. Inheritance in C++ has three access specifiers: public, protected, and private. When a base class is declared as private, its members are only accessible within the base class itself and not accessible by the derived class. Therefore, protected members of a private base class do not become public members of the derived class.
17.
When defining an iterator from the STL, the compiler automatically creates the right kind, depending upon the container it is to be used with.
Explanation
When defining an iterator from the STL, the compiler automatically creates the right kind, depending upon the container it is to be used with. This means that the compiler is able to determine the appropriate type of iterator to be used based on the type of container being iterated over. This allows for more efficient and accurate iteration, as the iterator will be specifically designed to work with the container in question.
18.
The base class destructor is called after the derived class destructor.
Explanation
In object-oriented programming, when a derived class is created from a base class, it inherits the properties and methods of the base class. When an object of the derived class is destroyed, its destructor is called first. After that, the destructor of the base class is called. This is because the derived class may have additional resources or memory allocated that need to be cleaned up before the base class is destroyed. Therefore, the statement "The base class destructor is called after the derived class destructor" is true.
19.
When both a base class and a derived class have constructors, the base class's constructor is called __________ (first/last).
Correct Answer
first
Explanation
When both a base class and a derived class have constructors, the base class's constructor is called first. This is because the derived class inherits the properties and behavior of the base class, and in order to properly initialize the derived class object, the base class constructor needs to be called first to set up the base class members. Once the base class constructor has executed, then the derived class constructor can be called to initialize the additional members specific to the derived class.
20.
A class template may not be derived from another class template
Explanation
A class template can be derived from another class template. This allows for the creation of a new class template that inherits the properties and behaviors of the base class template. Inheritance is a fundamental concept in object-oriented programming that allows for code reuse and the creation of more specialized classes. Therefore, the statement "A class template may not be derived from another class template" is false.
21.
__________ binding is when a function call is bound at runtime.
Correct Answer
dynamic
Explanation
Dynamic binding is when a function call is bound at runtime. This means that the specific function to be called is determined during the execution of the program, rather than being determined at compile time. This allows for more flexibility and adaptability in the code, as the appropriate function can be chosen based on the current state or context of the program.
22.
Protected members of a public base class become public members of the derived class.
Explanation
Protected members of a public base class do not become public members of the derived class. Instead, they become protected members of the derived class. This means that the derived class can access and modify these protected members, but they are not accessible to objects of the derived class or any other classes.
23.
A base class may not be derived from another class.
Explanation
This statement is false because a base class can indeed be derived from another class. In object-oriented programming, inheritance allows a class to inherit properties and methods from another class. The derived class, also known as a subclass or child class, can extend or modify the behavior of the base class, also known as a superclass or parent class. This is a fundamental concept in object-oriented programming and allows for code reuse and the creation of more specialized classes. Therefore, the correct answer is false.
24.
When an exception is thrown, but not caught, the program ignores the error.
Explanation
When an exception is thrown, but not caught, the program does not ignore the error. Instead, it terminates the program and displays an error message, indicating that an unhandled exception has occurred. This is because uncaught exceptions disrupt the normal flow of the program and can lead to unexpected behavior or crashes. Therefore, it is important to handle exceptions appropriately to ensure the program's stability and prevent unexpected errors.
25.
In C++, a class can inherit from multiple base classes.
Explanation
C++ supports multiple inheritance, allowing a class to inherit from multiple base classes. This enables code reuse and the creation of complex class hierarchies. However, multiple inheritance can also introduce complexities and potential ambiguities, requiring careful design and consideration.
26.
A(n) __________ member function in a base class expects to be overridden in a
derived class.
Correct Answer
virtual
Explanation
A virtual member function in a base class expects to be overridden in a derived class. This means that the derived class can provide its own implementation of the function, which will be called instead of the base class's implementation when the function is called through a pointer or reference to the base class. This allows for polymorphism, where different derived classes can have different behaviors for the same function.
27.
It is possible to overload a function template and an ordinary (nontemplate) function.
Explanation
Function overloading is a feature in C++ that allows multiple functions with the same name but different parameters. This feature applies to both function templates and ordinary (nontemplate) functions. By using function overloading, we can define multiple functions with the same name but different parameter types or different number of parameters. This allows us to handle different types of inputs or perform different operations based on the parameters passed to the function. Therefore, it is indeed possible to overload a function template and an ordinary function.
28.
The __________ block contains code that directly or indirectly might cause an exception to be thrown.
Correct Answer
try
Explanation
The try block contains code that is potentially risky or may encounter an error, and therefore it is surrounded by a try-catch statement. If an exception occurs within the try block, it can be caught and handled appropriately in the catch block. This allows for better control and management of potential exceptions in the code.
29.
__________ is when member functions in a class hierarchy behave differently, depending
upon which object performs the call.
Correct Answer
polymorphism
Explanation
Polymorphism is the concept in object-oriented programming where member functions in a class hierarchy can behave differently based on the object that performs the call. This allows for flexibility and code reusability as different objects can have their own unique implementations of the same function. Polymorphism is achieved through the use of virtual functions and function overriding, allowing for dynamic binding and runtime determination of which function to call based on the type of object.
30.
Once an exception has been thrown, it is not possible for the program to jump back to the throw point.
Explanation
Once an exception has been thrown, the program enters an exceptional state and the normal flow of execution is disrupted. The program then looks for an exception handler to catch and handle the exception. If an appropriate exception handler is not found, the program terminates. In this context, "jumping back to the throw point" refers to the program returning to the exact line of code where the exception was thrown. However, once an exception is thrown, the program does not automatically jump back to the throw point. Therefore, the statement is true.
31.
A class object passed to a function template must overload any operators used on the class object by the template.
Explanation
When passing a class object to a function template, it is necessary to overload any operators that are used on the class object by the template. This is because function templates are generic and can be used with different types of objects. To ensure that the operators are correctly applied to the class object, the overloaded operators must be defined for that specific class. Therefore, the statement "A class object passed to a function template must overload any operators used on the class object by the template" is true.
32.
A member function of a derived class may not have the same name as a
a member function of the base class.
Explanation
In object-oriented programming, it is common for a member function of a derived class to have the same name as a member function of the base class. This practice is known as function overriding, where the derived class provides a specific implementation of a function that is already defined in its base class. This allows for polymorphic behavior, enabling the derived class to modify or extend the functionality of the base class function.
33.
All type parameters defined in a function template must appear at least once in the function parameter list.
Explanation
While type parameters often appear in the function parameter list of a template, it's not a strict requirement. Type parameters can also be used to define the return type of the function or even within the function body to declare variables of that type. The key is that the type parameter must be used somewhere within the template definition, not necessarily just in the parameter list. This flexibility allows for more versatile and expressive template designs.
34.
Public members of a private base class become private members of the
derived class.
Explanation
In object-oriented programming, when a class is derived from a private base class, the public members of the base class are not directly accessible to the derived class or any other class. They become private members of the derived class, meaning they can only be accessed within the scope of the derived class itself. This is because the private access specifier restricts the visibility of the members to only the class in which they are defined. Therefore, the statement "Public members of a private base class become private members of the derived class" is true.
35.
Public members of a protected base class become private members of the derived class
Explanation
This statement is false. Inheritance in C++ allows the derived class to access the protected members of the base class. However, the access level does not change from protected to private. Protected members of the base class remain protected in the derived class, meaning they can still be accessed by the derived class and its derived classes.
36.
In multiple inheritances, the derived class should always __________ a function that
has the same name in more than one base class.
Correct Answer
override
redefine
Explanation
In multiple inheritances, the derived class should always override or redefine a function that has the same name in more than one base class. This is necessary because when a derived class inherits from multiple base classes, it may inherit multiple versions of the same function. To avoid ambiguity and ensure that the correct version of the function is used, the derived class must explicitly override or redefine the function.
37.
In the function template definition, it is not necessary to use each type parameter declared in the template prefix.
Explanation
In the function template definition, it is necessary to use each type parameter declared in the template prefix. This is because the type parameters are placeholders for the actual types that will be used when the function is instantiated. If a type parameter is not used in the function definition, it means that the function cannot handle that type of argument, which defeats the purpose of having a template in the first place. Therefore, it is important to use all the type parameters declared in the template prefix.
38.
The compiler creates an instance of a function template in memory as soon as it encounters the template.
Explanation
The compiler does not create an instance of a function template in memory as soon as it encounters the template. Instead, the compiler generates the code for the function template when it is instantiated, which happens when the template is used with specific template arguments. This allows the compiler to generate different versions of the function template for different types or values used as template arguments. Therefore, the correct answer is false.
39.
__________ is where a derived class has two or more base classes.
Correct Answer
multiple inheritance
Explanation
Multiple inheritance is a feature in object-oriented programming where a derived class can inherit from two or more base classes. This allows the derived class to inherit and combine the properties and behaviors of multiple parent classes. It provides flexibility and allows for code reuse by inheriting from multiple sources. However, it can also lead to complexity and potential conflicts if the same method or attribute is inherited from multiple base classes.
40.
__________ are pointer-like objects used to access data stored in a container.
Correct Answer
iterators
Explanation
Iterators are objects used to access data stored in a container. They act as pointer-like objects, allowing us to traverse through the elements of a container and perform various operations on them. By using iterators, we can access, modify, or delete elements in a container without directly manipulating the container itself. This provides a flexible and efficient way to work with container data, as it allows us to iterate over the elements in a controlled and organized manner.
41.
The base class's access specification affects the way base class member functions
may access base class member variables.
Explanation
The base class's access specification does not affect the way base class member functions access base class member variables. The access specification only determines the visibility of the member variables to derived classes and external functions, not to member functions of the base class itself. Therefore, the statement is false.
42.
__________ binding is when the compiler binds member function calls at compile time.
Correct Answer
static
Explanation
Static binding is when the compiler binds member function calls at compile time. This means that the compiler determines which function to call based on the type of the object at compile time, rather than at runtime. Static binding is used when the function being called is not virtual or when the object type is known at compile time. In this case, the correct answer is "static" because it accurately describes the type of binding where member function calls are resolved at compile time.
43.
A(n) __________ function has no body, or definition, in the class in which it is declared.
Correct Answer
pure virtual
Explanation
A pure virtual function is a function that has no body or definition in the class in which it is declared. It is declared using the "pure virtual" keyword and is intended to be overridden by derived classes. This allows the base class to provide a common interface for all derived classes, while leaving the implementation details to be defined by each individual derived class.
44.
A derived class inherits the __________ of its base class.
Correct Answer
members
Explanation
A derived class inherits the members of its base class. In object-oriented programming, a derived class is a class that is created from an existing class, known as the base class. The derived class inherits all the members of the base class, including variables, methods, and properties. This means that the derived class can access and use these members without having to redefine them. Inheritance allows for code reuse and promotes the concept of hierarchy in class relationships.
45.
A(n) __________ of inheritance is where one class is derived from a second class,
which in turn is derived from a third class.
Correct Answer
chain
Explanation
Inheritance is a mechanism in object-oriented programming where a class can inherit properties and behaviors from another class. In this case, the term "chain" is used to describe the type of inheritance where one class is derived from a second class, and the second class is derived from a third class. This creates a chain-like relationship between the classes, with each class inheriting from the one above it. This allows for the reuse of code and promotes code organization and modularity.
46.
The __________ exception is thrown when the new operator fails to allocate the requested amount of memory
Correct Answer
bad_alloc
Explanation
The bad_alloc exception is thrown when the new operator fails to allocate the requested amount of memory. This exception is part of the standard exception hierarchy in C++, and it is specifically designed to handle memory allocation failures. When the new operator is unable to allocate memory, it throws a bad_alloc exception, which can then be caught and handled by the programmer.
47.
A(n) __________ template works with a specific data type.
Correct Answer
specialized
Explanation
A specialized template is designed to work with a specific data type. It is tailored to handle and manipulate data of a particular type, providing optimized functionality and operations that are specific to that data type. This allows for more efficient and accurate processing of the data, as the template is specifically designed to handle the unique characteristics and requirements of that particular type.
48.
The line containing a throw statement is known as the __________.
Correct Answer
throw point
Explanation
The line containing a throw statement is known as the throw point.
49.
When a pointer to a base class is made to point to a derived class, the pointer ignores
any __________ the derived class performs, unless the function is __________.
Correct Answer
overrides, virtual
Explanation
When a pointer to a base class is made to point to a derived class, the pointer ignores any overrides the derived class performs, unless the function is virtual. This means that if a derived class has a function with the same name as a function in the base class, the pointer will call the function in the base class unless that function is declared as virtual in the base class. If the function is declared as virtual, the pointer will call the function in the derived class instead. This allows for polymorphism and dynamic binding of functions at runtime.