Java Generics Interview Questions And Answers

Here are Java Programming Generics Interview Questions and Answers for freshers asked in various companies. Here you can also download the Java Generics Quiz Questions PDF.
1. Why are generics used?
[A] Generics make code more fast.
[B] Generics make code more optimised and readable.
[C] Generics add stability to your code by making more of your bugs detectable at compile time.
[D] Generics add stability to your code by making more of your bugs detectable at run time.
Loading...
2. Which of these type parameters is used for a generic class to return and accept any type of object?

[A] K
[B] N
[C] T
[D] V
Loading...
3. Which of these type parameters is used for a generic class to return and accept a number?
[A] K
[B] N
[C] T
[D] V
Loading...
4. Which of these is an correct way of defining generic class?
[A] class name(T1, T2, …, Tn) { /* … */ }
[B] class name { /* … */ }
[C] class name[T1, T2, ..., Tn] { /* … */ }
[D] class name{T1, T2, …, Tn} { /* … */ }
Loading...
5. Which of the following is incorrect statement regarding the use of generics and parameterized types in Java?

[A] Generics provide type safety by shifting more type checking responsibilities to the compiler.
[B] Generics and parameterized types eliminate the need for down casts when using Java Collections.
[C] When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve
[D] All of the mentioned
Loading...
6. Which of the following reference types cannot be generic?

[A] Anonymous inner class
[B] Interface
[C] Inner class
[D] All of the mentioned
Loading...
7. What is the output of this program?

1. import java.util.*;
2. public class genericstack {
3. Stack stk = new Stack ();
4. public void push(E obj) {
5. stk.push(obj);
6. }
7. public E pop() {
8. E obj = stk.pop();
9. return obj;
10. }
11. }
12. class Output {
13. public static void main(String args[]) {
14. genericstack gs = new genericstack();
15. gs.push("Hello");
16. System.out.println(gs.pop());
17. }
18. }
[A] H
[B] Hello
[C] Runtime Error
[D] Compilation Error
Loading...
8. Which of these types cannot be used to initiate a generic type?

[A] Integer class
[B] Float class
[C] Primitive Types
[D] Collections
Loading...
9. Which of these instance cannot be created?

[A] Integer instance.
[B] Generic class instance.
[C] Generic type instance.
[D] Collection instances.
Loading...
10. Which of these data type cannot be type parameterized?
[A] Array
[B] List
[C] Map
[D] Set
Loading...
Are these questions helpful for you?

Comments: (Your feedback is valuable to us)