1.

Which of these is an correct way of defining generic method?(a) name(T1, T2, …, Tn) { /* … */ }(b) public name { /* … */ }(c) class name[T1, T2, …, Tn] { /* … */ }(d) name{T1, T2, …, Tn} { /* … */ }I have been asked this question in an internship interview.The question is from Generic Methods topic in portion Generics of Java

Answer»

The correct option is (b) public NAME { /* … */ }

The explanation is: The syntax for a generic METHOD includes a TYPE parameter, inside ANGLE brackets, and appears before the method’s return type. For static generic methods, the type parameter section must appear before the method’s return type.



Discussion

No Comment Found

Related InterviewSolutions