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

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

Q.42Medium

Which wildcard usage follows the Producer pattern?

Q.43Medium

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

Q.44Medium

What is the PECS principle in Java Generics?

Q.45Medium

Which of these is a valid generic interface implementation?

Q.46Medium

What is the runtime class object for this generic variable?
java
List<String> list = new ArrayList<String>();
Class<?> c = list.getClass();

Q.47Medium

A developer creates a generic method that accepts a collection of numbers and calculates their sum. Which type parameter declaration would be most appropriate for this scenario?

Q.48Medium

A utility class needs a method that accepts a List containing elements that are instances of a specific class or its subclasses. Which wildcard notation should be used?

Q.49Medium

In a microservices architecture, you're designing a Response wrapper class that should work with any data type, including primitives when boxed. Which implementation is correct?