What will be the result of executing: List<Integer> list = new ArrayList<String>();
Q.42Medium
Which statement correctly defines a generic class with multiple type parameters and bounds?
Q.43Medium
Consider: public static <T> T findMax(T a, T b) { return a; }. What is the issue with calling findMax(5, 3.5)?
Q.44Medium
What does List<?> represent in Java generics?
Q.45Medium
Which of the following will NOT compile?
Advertisement
Q.46Easy
What is the output of the following code?
List<Integer> list = new ArrayList<Integer>();
list.add(10);
Object obj = list.get(0);
System.out.println(obj.getClass().getName());
Q.47Medium
Consider a generic interface: interface Comparable<T> { int compareTo(T obj); }. How should a class implement this for String comparison?
Q.48Medium
What happens when you use raw type List instead of List<String>?
Q.49Hard
Which generic declaration allows a method to accept List of any type?
Q.50Hard
What is the difference between <T extends Comparable<T>> and <T extends Comparable>?
Q.51Hard
Can you create an instance of generic type parameter directly like: T obj = new T();?
Q.52Hard
What is the PECS principle in generics?
Q.53Hard
Which statement about generic constructors is TRUE?
Q.54Medium
What is the output?
List<String> strings = new ArrayList<String>();
List list = strings;
list.add(123);
String str = strings.get(0);
System.out.println(str);
Q.55Medium
How would you define a generic method that works with a pair of objects and returns the first one?
Q.56Easy
What is the advantage of using generics over raw types in terms of 2024-25 Java standards?
Q.57Easy
Which of the following is a valid generic class declaration in Java?
Q.58Easy
What is the result of type erasure in Java generics?
Q.59Medium
Consider the following code snippet:
public <T> T processData(List<? extends T> list) { return list.get(0); }
What is the relationship between the wildcard and type parameter T?
Q.60Medium
Which of the following will cause a compile-time error?