iGET

Java Programming - MCQ Practice Questions

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

951 questions | 100% Free

Q.741Medium

What happens when you use raw type List instead of List<String>?

Q.742Hard

Which generic declaration allows a method to accept List of any type?

Q.743Hard

What is the difference between <T extends Comparable<T>> and <T extends Comparable>?

Q.744Hard

Can you create an instance of generic type parameter directly like: T obj = new T();?

Q.745Hard

What is the PECS principle in generics?

Q.746Hard

Which statement about generic constructors is TRUE?

Q.747Medium

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

How would you define a generic method that works with a pair of objects and returns the first one?

Q.749Easy

What is the advantage of using generics over raw types in terms of 2024-25 Java standards?

Q.750Easy

Which of the following is a valid generic class declaration in Java?

Q.751Easy

What is the result of type erasure in Java generics?

Q.752Medium

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

Which of the following will cause a compile-time error?

Q.754Medium

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

Q.755Medium

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

Q.756Medium

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

Q.757Hard

Which statement correctly implements a generic factory method?

Q.758Easy

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

Q.759Medium

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

Q.760Easy

What does the wildcard in List<?> represent?