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

Which generic wildcard usage follows the consumer pattern correctly?

Q.762Hard

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

Q.763Medium

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

Q.764Medium

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

Q.765Medium

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

Q.766Hard

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

Q.767Easy

What is the relationship between generics and arrays in Java?

Q.768Medium

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

Q.769Hard

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

Q.770Easy

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

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

Q.772Easy

Which declaration is valid in Java Generics?

Q.773Medium

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

Q.774Medium

Consider the code:
java
List<Number> list = new ArrayList<Integer>();

Will this compile?

Q.775Medium

What is the correct output of this code?
java
List<? extends Number> list = new ArrayList<Integer>();
list.add(5);

Q.776Medium

Which wildcard usage follows the Producer pattern?

Q.777Medium

What does 'covariance' mean in the context of Java Generics?

Q.778Medium

What is the PECS principle in Java Generics?

Q.779Medium

Which of these is a valid generic interface implementation?

Q.780Hard

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);