Test Series - oops

Test Number 33/78

Q: A template class defines the form of a class _____________________ it will operate.
A. With full specification of the data on which
B. With full specification of the functions on which
C. Without full specification of the data on which
D. Without full specification of the functions on which
Solution: The template classes can accept all types of data types. There is no need to specify the data on which the class has to operate. Hence it gives us flexibility to code without worrying about the type of data that might be used in the code.
Q: What are the two specializations of I/O template classes in C++?
A. 16-bit character and wide characters
B. 8-bit character and wide characters
C. 32-bit character and locale characters
D. 64-bit characters and locale characters
Solution: The I/O specialization is made with wide character and 8-bit characters. Wide characters are used to store the characters that might take more than 1 byte of space in memory or any size that is different from the one that the machine is using.
Q: Can typeid() function be used with the object of generic classes?
A. Yes, only if default type is given
B. Yes, always
C. No, generic data can’t be determined
D. No, never possible
Solution: The typeid() function can be used with the objects of generic classes. An instance of a template class will take the type of data that is being used with it. Hence when typeid() function is used, the data type would have already been defined and hence we can get desired result from typeid() function.
Q: The _____________ class is a specialization of a more general template class.
A. String
B. Integer
C. Digit
D. Math
Solution: The string class is more specialized. Since the string must be able to store any kind of data that is given to the string. Hence it needs maximum specialization.
Q: How is function overloading different from template class?
A. Overloading is multiple function doing same operation, Template is multiple function doing different operations
B. Overloading is single function doing different operations, Template is multiple function doing different operations
C. Overloading is multiple function doing similar operation, Template is multiple function doing identical operations
D. Overloading is multiple function doing same operation, Template is same function doing different operations
Solution: The function overloading is multiple functions with similar or different functionality but generic class functions perform the same task on given different types of data.
Q: What if static members are declared inside template classes?
A. All instances will share the static variable
B. All instances will have their own static variable
C. All the instances will ignore the static variable
D. Program gives compile time error
Solution: The generic class have a special case with static members. Each instance will have its own static member. The static members are not shared usually.
Q: If template class is defined, is it necessary to use different types of data for each call?
A. No, not necessary
B. No, but at least two types must be there
C. Yes, to make proper use of template
D. Yes, for code efficiency
Solution: It is not necessary to use different type with each call to the generic function. Data may be of same type with each call but still the function works. We don’t consider other properties like efficiency with this concept because it is made generic to all data type, hence always works.
Q: How many generic types can be given inside a single template class?
A. Only 1
B. Only 3
C. Only 7
D. As many as required
Solution: There is no restriction on the number of types to be used for making the class generic. There can be any number of generic types with a single class. Hence giving flexibility to code with all the data types.
Q: Which is most appropriate definition of a base class?
A. It is parent of any of its derived class
B. It is child of one of the parent class
C. It is most basic class of whole program
D. It is class with maximum number of members
Solution: A class which is parent of another class, or from which other classes can be derived, is known as a base class. It is mandatory that a class must have at least one derived class to be called as a base class.
Q: A base class is also known as _____________ class.
A. Basic
B. Inherited
C. Super
D. Sub
Solution: A class which is being derived by other classes, is called as super class. This concept is clearly used in java as we call the functions of a base class by using the keyword super as required.

You Have Score    /10