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.761Medium

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

Q.762Medium

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

Q.763Medium

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

Q.764Hard

Which statement correctly implements a generic factory method?

Q.765Easy

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

Q.766Medium

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

Q.767Easy

What does the wildcard in List<?> represent?

Q.768Hard

Which generic wildcard usage follows the consumer pattern correctly?

Q.769Hard

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

Q.770Medium

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

Q.771Medium

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

Q.772Medium

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

Q.773Hard

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

Q.774Easy

What is the relationship between generics and arrays in Java?

Q.775Medium

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

Q.776Hard

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

Q.777Easy

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.778Easy

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

Q.779Easy

Which declaration is valid in Java Generics?

Q.780Medium

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