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

What is the output of this generic code? class Pair<K, V> { public void display(K key, V value) { System.out.println(key + ": " + value); } } Pair<String, Integer> p = new Pair<>(); p.display("Age", 25);

Q.202Easy

In Java generics, what does the wildcard '?' represent?

Q.203Easy

What is the primary advantage of using generics in Java?

Q.204Easy

Which of the following will compile successfully?

Q.205Easy

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

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

Q.207Easy

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

Q.208Easy

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

Q.209Easy

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

Q.210Easy

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

What is the advantage of using generics over raw types in terms of 2024-25 Java standards?

Q.212Easy

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

Q.213Easy

What is the result of type erasure in Java generics?

Q.214Easy

What is the compiler-inferred type parameter in this call? List<String> list = Arrays.asList("a", "b", "c");

Q.215Easy

What does the wildcard in List<?> represent?

Q.216Easy

What is the relationship between generics and arrays in Java?

Q.217Easy

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

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

Q.219Easy

Which declaration is valid in Java Generics?

Q.220Easy

In a Spring Boot application, you need to create a generic repository interface that works with any entity type. Which declaration correctly implements this pattern?