Java Generics Interview Questions

    Question 1: JAVA - Generics Basics

    What is the main purpose of Generics in Java?

    Question 2: JAVA - Generic Class

    Which of the following correctly defines a generic class?

    Question 3: JAVA - Generic Method

    Which syntax is correct for a generic method?

    Question 4: JAVA - Type Safety Example

    What will happen in this code?

    List list = new ArrayList(); list.add("Hello"); list.add(10); String s = (String) list.get(1); System.out.println(s);

    Question 5: JAVA - Wildcard ?

    What does the wildcard ? represent in generics?

    Question 6: JAVA - Upper Bounded Wildcard

    Which declaration is correct for a list of numbers (Integer, Double, etc.)?