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

What is the primary purpose of Generics in Java?

Q.702Easy

Which keyword is used to declare a generic class in Java?

Q.703Easy

What will be the output of the following code? List<String> list = new ArrayList<>(); list.add("Java"); System.out.println(list.get(0).length());

Q.704Easy

Which of the following is a valid generic method declaration?

Q.705Medium

What is type erasure in Java Generics?

Q.706Medium

Which statement about wildcard generics (?) is correct?

Q.707Medium

What will happen when you try to create an array of generics? List<String>[] array = new List<String>[10];

Q.708Medium

Consider the code: List<? extends Number> list = new ArrayList<>(); list.add(5); // Will this compile?

Q.709Medium

Which of the following represents a bounded type parameter?

Q.710Medium

What is the difference between List<?> and List<Object>?

Q.711Medium

Consider this generic interface: interface Comparable<T> { int compareTo(T o); } Which class definition correctly implements this?

Q.712Medium

What will be the output? List<Integer> list = new ArrayList<>(); list.add(10); Object obj = list.get(0); System.out.println(obj instanceof Integer);

Q.713Hard

Which of these correctly demonstrates the Producer Extends Consumer Super (PECS) principle?

Q.714Hard

What will happen with this code? List list = new ArrayList<String>(); list.add(123); // Adding Integer String s = (String) list.get(0);

Q.715Hard

Consider this code: public <T extends Comparable<T>> T getMax(T a, T b) { return a.compareTo(b) > 0 ? a : b; } What is the benefit of this recursive bound <T extends Comparable<T>>?

Q.716Easy

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

Which statement is true about generic inheritance?

Q.718Hard

What will be the result of this code? List<String> list = new ArrayList<>(); list.add("Hello"); List raw = list; // Unchecked assignment raw.add(123); // Adding Integer to raw type String s = list.get(1);

Q.719Medium

Which of these declarations would NOT cause a compilation warning or error?

Q.720Easy

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