Chapter 9 Subprograms of Concepts of Programming Languages MCQ 29. In Java, rest
ID: 3706110 • Letter: C
Question
Chapter 9 Subprograms of Concepts of Programming Languages MCQ
29. In Java, restrictions can be specified on the range of classes that can be passed to the generic method as generic parameters. Such restrictions are called ____.
A. bound
B. non-free
C. polymorphic
D. wildcard
E. primitive
30. In Java, the expression <T extends BoundingType> specifies that T should be a(n) ____ of the bounding type.
A. ad-hoc
B. generic
C. inheritance
D. subtype
E. supertype
31. In Java, if a generic method has two or more restrictions on its generic type, they are added to the extends-clause, separated by _____.
A. comma
B. semicolon
C. ampersand
D. plus
E. star
32. Java 5.0 supports ____ types which can be used for any collection type of any class components.
A. bound
B. generic
C. polymorphic
D. wildcard
E. primitive
35. Function object or functor is another name for ____ time to time.
A. abstract class
B. parametric object
C. polymorphic object
D. standard template object
E. subtype class
F. object closure
G. object template
Explanation / Answer
29) A) Bound
public static <T extends Comparable> T checkGeneric(T[] genData)
{
// Body of the method
}
The above method takes a generic array parameter named as genData. The elements of the array are of a class that implements the Comparable interface.
This is called the bound or restrictions, on the generic parameter.
30) D) subtype
<T extends BoundingType>
In the above expression extends T is a subtype of the BoundingType.
In the above expression extends means generic (class / interface) either extends the bounding class (if the bound is a class) or implements the bounding interface (if the bound is an interface).
31) C) ampersand
class One { /* ... */ }
interface Two { /* ... */ }
interface Three { /* ... */ }
class MyClass <T extends One & Two & Three> { /* ... */ }
If bound One is not specified first, we will get a compile-time error message.
32) D) wildcard
Collection <?>
In the above example, ? (question mark) is a wild card type for collection class.