Generic Methods QuizS2C Home « Generic Methods Quiz

Generics Quiz 9

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

Question 1 : Is it possible to have generic methods inside non-generic classes?
- It IS possible to have generic methods inside non-generic classes.
Question 2 : Is the following code snippet a valid example of a generic method?
public <T extends Number> void genMethod (T number) { ... }
- The code snippet IS a valid example of a non-static generic method.
Question 3 : When declaring a generic method in a non-generic class we have to declare the generic type after the return type within the method?
- When declaring a generic method in a non-generic class we have to declare the generic type BEFORE the return type within the method.
Question 4 : Is the following code snippet a valid example of a generic method?
public static void <T extends Number> genMethod (T number) { ... }
- The code snippet is INVALID as the return type must follow the generic type in a generic method.
Question 5 : Generic methods must be static?
- Generic methods can be static or non-static.
Question 6 : Is the following code snippet a valid example of a generic method?
public static <T extends Number> void genMethod (T number) { ... }
- The code snippet IS a valid example of a static generic method.
Quiz Progress Bar Please select an answer


What's Next?

In the next quiz we test your knowledge of generic constructors.