Generic Constructors QuizS2C Home « Generic Constructors Quiz

Generics Quiz 10

The quiz below tests your knowledge of the material learnt in Generics - Lesson 10 - Generic Constructors.

Question 1 : Is the following code snippet a valid example of a generic constructor?
public CubeNumber (T number) <T extends Number> { ... }
- When declaring a generic constructor in a non-generic class we have to declare the generic type BEFORE the constructor name so the code is invalid.
Question 2 : Is it possible to have generic constructors inside non-generic classes?
- It IS possible to have generic constructors inside non-generic classes.
Question 3 : The following code snippet is a valid example of a generic method?
public static <T extends Number> CubeNumber (T number) { ... }
- The code snippet is INVALID as the static keyword is not allowed in a contructor.
Question 4 : Generic constructors can be static or non-static?
- All constructors including generic ones instantiate objects and are therefore by defintion non-static.
Question 5 : When declaring a generic constructor in a non-generic class we have to declare the generic type before the constructor name?
- When declaring a generic constructor in a non-generic class we have to declare the generic type BEFORE the constructor name.
Question 6 : Is the following code snippet a valid example of a generic constructor?
public <T extends Number> CubeNumber (T number) { ... }
- The code snippet IS a valid example of a static generic method.
Quiz Progress Bar Please select an answer


What's Next?

That's it for the generic quizzes, the next set of quizzes are on streams.