Test Series - cpp

Test Number 45/102

Q: What is meant by container ship?
A. class contains objects of other class types as its members
B. class contains objects of other class types as its objects
C. class contains objects of other class types as its members 7 also objects
D. class contains objects of other class types as its members 9 also objects
Solution: Container ship is a class contains objects of other class types as its members.
Q: How many types of the constructor are there in C++?
A. 1
B. 2
C. 3
D. 4
Solution: There are three types of constructor in C++. They are the Default constructor, Parameterized constructor, Copy constructor.
Q: How many constructors can present in a class?
A. 1
B. 2
C. 3
D. multiple
Solution: There can be multiple constructors of the same class, provided they have different signatures.
Q: 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 function
Solution: Constructor name should be same as the class name.
Q: What does derived class does not inherit from the base class?
A. constructor and destructor
B. friends
C. operator = () members
D. all of the mentioned
Solution: The derived class inherits everything from the base class except the given things.
Q: What is a template?
A. A template is a formula for creating a generic class
B. A template is used to manipulate the class
C. A template is used for creating the attributes
D. A template is used to delete the class
Solution: Templates are used for creating generic classes to handle different types in single classes.
Q: Pick out the correct statement about string template.
A. It is used to replace a string
B. It is used to replace a string with another string at runtime
C. It is used to delete a string
D. It is used to create a string
Solution: Every string template is used to replace the string with another string at runtime.
Q: How to declare a template?
A. tem
B. temp
C. template<>
D. temp()
Solution: template<> syntax is used.
An example for calculating max of two ints, floats, doubles, or any other number type where T indicates the type of the parameters passes.
template 
T max(T a, T b){
return a > b? a : b;
}
Q: Which are done by compiler for templates?
A. type-safe
B. portability
C. code elimination
D. prototype
Solution: The compiler can determine at compile time whether the type associated with a template definition can perform all of the functions required by that template definition.
Q: What may be the name of the parameter that the template should take?
A. same as template
B. same as class
C. same as function
D. same as member
Solution: The name of the parameter that the template should take same as the template.

You Have Score    /10