iGET

Java Programming - MCQ Practice Questions

Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.

958 questions | 100% Free

Q.381Medium

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

Q.382Medium

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

Q.383Medium

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

Q.384Medium

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

Q.385Medium

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

Q.386Medium

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

Q.387Medium

Which wildcard usage follows the Producer pattern?

Q.388Medium

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

Q.389Medium

What is the PECS principle in Java Generics?

Q.390Medium

Which of these is a valid generic interface implementation?

Q.391Medium

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

Q.392Medium

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

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

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?

Q.395Medium

Which of the following lambda expressions is invalid?

Q.396Medium

What is the type of the following lambda expression: x -> x.length()?

Q.397Medium

Which functional interface should be used for a lambda that filters elements?

Q.398Medium

What will this code print? List<Integer> list = Arrays.asList(1, 2, 3, 4, 5); list.forEach(x -> System.out.print(x + " "));

Q.399Medium

Can lambda expressions access local variables from their enclosing scope?

Q.400Medium

Which of the following correctly represents a BiFunction?