Java Generics Interview Questions

    Question 1JAVA - Generics Basics

    What is the main purpose of Generics in Java?

    Question 2JAVA - Generic Class

    Which of the following correctly defines a generic class?

    Question 3JAVA - Generic Method

    Which syntax is correct for a generic method?

    Question 4JAVA - 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 5JAVA - Wildcard ?

    What does the wildcard ? represent in generics?

    Question 6JAVA - Upper Bounded Wildcard

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