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.161Hard

What will be the result of this code?
List<String> list = new ArrayList<>();
list.add("Hello");
List raw = list; // Unchecked assignment
raw.add(123); // Adding Integer to raw type
String s = list.get(1);

Q.162Hard

What will happen when you try to create an array of generic types like 'new ArrayList<String>[10]'?

Q.163Hard

Consider: Map<String, ? extends List<?>> map = new HashMap<>();

What can you safely retrieve from this map?

Q.164Hard

What is the key difference between '? extends T' and '? super T' in practical usage?

Q.165Hard

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

Q.166Hard

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

Q.167Hard

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

Q.168Hard

What is the PECS principle in generics?

Q.169Hard

Which statement about generic constructors is TRUE?

Q.170Hard

Which statement correctly implements a generic factory method?

Q.171Hard

Which generic wildcard usage follows the consumer pattern correctly?

Q.172Hard

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

Q.173Hard

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

Q.174Hard

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

Q.175Hard

What will happen when you compile and run this code?
java
List<String> strings = Arrays.asList("a", "b", "c");
List raw = strings;
raw.add(123);
String s = strings.get(3);

Q.176Hard

Consider this declaration: public static <T> List<T> createList(). Which statement about type inference is correct?

Q.177Hard

What is the difference between List<Object> and List<?> in practical usage?

Q.178Hard

What is the compiled bytecode signature of this generic method?
public <T extends Comparable<T>> T findMin(T[] arr)

Q.179Hard

Which statement about generic array creation is correct?

Q.180Hard

What output will this produce?
java
List<? super Integer> list = new ArrayList<Number>();
list.add(5);
Integer val = (Integer) list.get(0);