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

What is type erasure in Java Generics?

Q.2Medium

Which statement about wildcard generics (?) is correct?

Q.3Medium

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

Q.4Medium

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

Q.5Medium

Which of the following represents a bounded type parameter?

Q.6Medium

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

Q.7Medium

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

Q.8Medium

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

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

Q.10Medium

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

Q.11Medium

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

Q.12Medium

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

Q.13Medium

What does the PECS principle stand for in generics context?

Q.14Medium

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

Q.15Medium

Which generic wildcard usage is INCORRECT?

Q.16Medium

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

Q.17Medium

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

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

Q.19Medium

Which statement about generic type parameters is TRUE?

Q.20Medium

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