iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.361Medium

Consider the declaration: List<? super Integer> list. What does this wildcard represent?

Q.362Medium

Which statement correctly defines a generic class with multiple type parameters and bounds?

Q.363Medium

Consider: public static <T> T findMax(T a, T b) { return a; }. What is the issue with calling findMax(5, 3.5)?

Q.364Medium

What does List<?> represent in Java generics?

Q.365Medium

Which of the following will NOT compile?

Q.366Medium

Consider a generic interface: interface Comparable<T> { int compareTo(T obj); }. How should a class implement this for String comparison?

Q.367Medium

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

Q.368Medium

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

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

Q.370Medium

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

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

Q.372Medium

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

Q.373Medium

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

Q.374Medium

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

Q.375Medium

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

Q.376Medium

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

Q.377Medium

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

Q.378Medium

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

Q.379Medium

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

Q.380Medium

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