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

Which of these correctly demonstrates the Producer Extends Consumer Super (PECS) principle?

Q.2Hard

What will happen with this code?
List list = new ArrayList<String>();
list.add(123); // Adding Integer
String s = (String) list.get(0);

Q.3Hard

Consider this code:
public <T extends Comparable<T>> T getMax(T a, T b) {
return a.compareTo(b) > 0 ? a : b;
}
What is the benefit of this recursive bound <T extends Comparable<T>>?

Q.4Hard

Which statement is true about generic inheritance?

Q.5Hard

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

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

Q.7Hard

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

What can you safely retrieve from this map?

Q.8Hard

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

Q.9Hard

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

Q.10Hard

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

Q.11Hard

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

Q.12Hard

What is the PECS principle in generics?

Q.13Hard

Which statement about generic constructors is TRUE?

Q.14Hard

Which statement correctly implements a generic factory method?

Q.15Hard

Which generic wildcard usage follows the consumer pattern correctly?

Q.16Hard

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

Q.17Hard

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

Q.18Hard

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

Q.19Hard

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

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