Self-Review Exercises

  1. 20.1 State whether each of the following is true or false. If false, explain why.

    1. A generic method cannot have the same method name as a nongeneric method.

    2. All generic method declarations have a type-parameter list that immediately precedes the method name.

    3. A generic method can be overloaded by another generic method with the same method name but a different number of type parameters.

    4. A type parameter can be declared only once in the type-parameter list but can appear more than once in the method’s parameter list.

    5. Type-parameter names among different generic methods must be unique.

    6. The scope of a generic class’s type parameter is the entire class.

    7. A type parameter can have at most one interface constraint, but multiple class constraints.

  2. 20.2 Fill in the blanks in each of the following:

    1.                      enable you to specify, with a single method declaration, a set of related methods;                      enable you to specify, with a single class declaration, a set of related classes.

    2. A type-parameter list is delimited by                     .

    3. The                      of a generic method can be used to specify the types of the arguments to the method, to specify the return type of the method and to declare variables within the method.

    4. The statement “Stack<int> myStack = new Stack<int>();” indicates that myStack stores                     .

    5. In a generic class declaration, the class name is followed by a(n)                     .

    6. The                      constraint requires that the type argument must have a public parameterless constructor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset