iGET

Java Programming - MCQ Practice Questions

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

951 questions | 100% Free

Q.721Easy

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

Which generic wildcard usage is INCORRECT?

Q.723Medium

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

Q.724Medium

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

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

Q.726Easy

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

Q.727Medium

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

Q.728Hard

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

Q.729Medium

Which statement about generic type parameters is TRUE?

Q.730Hard

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

Q.731Easy

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

Q.732Easy

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

Q.733Medium

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

Q.734Easy

What will be the result of executing: List<Integer> list = new ArrayList<String>();

Q.735Medium

Which statement correctly defines a generic class with multiple type parameters and bounds?

Q.736Medium

Consider: public static <T> T findMax(T a, T b) { return a; }. What is the issue with calling findMax(5, 3.5)?

Q.737Medium

What does List<?> represent in Java generics?

Q.738Medium

Which of the following will NOT compile?

Q.739Easy

What is the output of the following code? List<Integer> list = new ArrayList<Integer>(); list.add(10); Object obj = list.get(0); System.out.println(obj.getClass().getName());

Q.740Medium

Consider a generic interface: interface Comparable<T> { int compareTo(T obj); }. How should a class implement this for String comparison?