iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

958 questions | 100% Free

Q.61Medium

What does the following generic method signature indicate? public static <T extends Comparable<T>> T findMax(T[] array)

Q.62Medium

Given: Map<String, ? extends List<?>> map = new HashMap<>(); Which operation is valid?

Q.63Medium

What is the output of this code? List<String> strings = new ArrayList<>(); List raw = strings; raw.add(123); String str = strings.get(0);

Q.64Hard

Which statement correctly implements a generic factory method?

Q.65Easy

What is the compiler-inferred type parameter in this call? List<String> list = Arrays.asList("a", "b", "c");

Q.66Medium

Consider: public class Pair<T, U> { } Which declaration is invalid?

Q.67Easy

What does the wildcard in List<?> represent?

Q.68Hard

Which generic wildcard usage follows the consumer pattern correctly?

Q.69Hard

What is the compiled signature of this generic method? public <T extends Number & Comparable<T>> void sort(T[] array)

Q.70Medium

What is the correct way to declare a generic method that accepts a list and returns the maximum element?

Q.71Medium

Given the declaration: List<List<String>> listOfLists; Which assignment is valid?

Q.72Medium

What happens when you try to cast a generic object? List<String> strings = (List<String>) getSomeList();

Q.73Hard

Which of the following represents valid bounded wildcard usage for a method that processes collections?

Q.74Easy

What is the relationship between generics and arrays in Java?

Q.75Medium

In the context of generics, what does 'invariance' mean?

Q.76Hard

How would you correctly use generics in a recursive type bound scenario?

Q.77Easy

What will be the output of the following code? java List<String> list = new ArrayList<String>(); list.add("Java"); Object obj = list; System.out.println(list.getClass() == obj.getClass());

Q.78Easy

Which of the following correctly declares a generic method that returns the first element of any collection?

Q.79Easy

Which declaration is valid in Java Generics?

Q.80Medium

What does the following generic declaration mean? public <T extends Number & Comparable<T>> T findMax(T a, T b)