Test Series - oops

Test Number 32/78

Q: Abstract class can’t be final in java.
A. True
B. False
C. 1
D. 0
Solution: If an abstract class is made final in java, it will stop the abstract class from being extended. And if the class is not getting extended, there won’t be another class to implement the virtual functions. Due to this contradicting fact, it can’t be final in java.
Q: Can abstract classes have static methods (Java)?
A. Yes, always
B. Yes, but depends on code
C. No, never
D. No, static members can’t have different values
Solution: There is no restriction on declaring static methods. The only condition is that the virtual functions must have some definition in the program.
Q: It is _________________________ to have an abstract method.
A. Not mandatory for an static class
B. Not mandatory for a derived class
C. Not mandatory for an abstract class
D. Not mandatory for parent class
Solution: Derived, parent and static classes can’t have abstract method (We can’t say what type of these classes is). And for abstract class it’s not mandatory to have abstract method. But if any abstract method is there inside a class, then class must be abstract type.
Q: How many abstract classes can a single program contain?
A. At most 1
B. At least 1
C. At most 127
D. As many as required
Solution: There is no restriction on the number of abstract classes that can be defined inside a single program. The programs can use as many abstract classes as required. But the functions with no body must be implemented.
Q: Is it necessary that all the abstract methods must be defined from an abstract class?
A. Yes, depending on code
B. Yes, always
C. No, never
D. No, if function is not used, no definition is required
Solution: That is the rule of programming language that each function declared, must have some definition. There can’t be some abstract method that remains undefined. Even if it’s there, it would result in compile time error.
Q: A template class can have _____________
A. More than one generic data type
B. Only one generic data type
C. At most two data types
D. Only generic type of integers and not characters
Solution: The template class can support more than one data type. The only thing is to add all the data types required in a list separated by comma within template specification.
Q: Which among the following is the proper syntax for the template class?
A. template ;
B. Template ;
C. template T named(T x, T y){ }
D. Template T1 named(T1 x, T2 y){ }
Solution: The syntax must start with keyword template, case sensitive. Then it should include the typename and a variable to denote it. Then whenever that variable is used, it replaces it with the data type needed.
Q: Can default arguments be used with the template class?
A. Yes, in some special cases
B. Yes, always
C. No, it must satisfy some specific conditions first
D. No, it can’t be done
Solution: The template class can use default arguments. This is used to specify the data type to be considered if it is not specified while passing to the generic class. The default type will be used.
Q: What is the syntax to use explicit class specialization?
A. template class myClass<>{ }
B. template class myClass{ }
C. template <> class myClass<>{ }
D. template <> class myClass{ }
Solution: The class specialization is creation of explicit specialization of a generic class. We have to use template<> constructor for this to work. It works in the same way as with explicit function specialization.
Q: Which is the most significant feature that arises by using template classes?
A. Code readability
B. Ease in coding
C. Code reusability
D. Modularity in code
Solution: The code reusability is the feature that becomes more powerful with the use of template classes. You can generate a single code that can be used in variety of programming situations.

You Have Score    /10