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

What is the primary advantage of using generics in Java?

Q.722Medium

In the declaration 'List<? extends Number> list', what types can be added to this list at runtime?

Q.723Medium

Which statement correctly uses the lower-bounded wildcard in generics?

Q.724Medium

Which generic declaration would allow storing both String and Integer in the same collection?

Q.725Medium

What does the PECS principle stand for in generics context?

Q.726Easy

Which of the following will compile successfully?

Q.727Medium

In a generic class 'class Box<T extends Comparable<T>>', what constraint is placed on T?

Q.728Easy

What is the output of this code snippet? ArrayList<String> list = new ArrayList<>(); list.add("Java"); Object obj = list.get(0); String str = (String) obj; System.out.println(str.length());

Q.729Medium

Which generic wildcard usage is INCORRECT?

Q.730Medium

What is the relationship between raw types and generics in Java?

Q.731Medium

Consider the method: public static <T> T getFirst(List<T> list) { return list.get(0); } How would you call this method for a List<String>?

Q.732Hard

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

Q.733Easy

In the interface declaration 'interface Pair<K, V>', how many type parameters does it have?

Q.734Medium

What is the significance of the '&' operator in generic bounds like '<T extends A & B>'?

Q.735Hard

Consider: Map<String, ? extends List<?>> map = new HashMap<>(); What can you safely retrieve from this map?

Q.736Medium

Which statement about generic type parameters is TRUE?

Q.737Hard

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

Q.738Easy

Which of the following is a valid generic method declaration in Java?

Q.739Easy

What is the primary purpose of bounded type parameters in generics?

Q.740Medium

Consider the declaration: List<? super Integer> list. What does this wildcard represent?