Skip to main content

Generics In Java — Part 2 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Generics In Java — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
10
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
12 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
10

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/10 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 10
★ FPSC ★ PPSC

What will be the output of the following Java program? import java.util.*; class Output { public static void addNumbers(List<? super Integer> list) { for (int i = 1; i <= 10; i++) { list.add(i); } } public static void main(String args[]) { List<Double> ld = Arrays.asList(); addnumbers(10.4); System.out.println("getList(2)"); } }

Question 2 of 10
★ FPSC ★ PPSC

Which of these is an correct way making a list that is upper bounded by class Number?

Question 3 of 10
★ FPSC ★ PPSC

What will be the output of the following Java program? public class BoxDemo { public static <U> void addBox(U u, java.util.List<Box<U>> boxes) { Box<U> box = new Box<>(); box.set(u); boxes.add(box); } public static <U> void outputBoxes(java.util.List<Box<U>> boxes) { int counter = 0; for (Box<U> box: boxes) { U boxContents = box.get(); System.out.println("Box #" + counter + " contains [" + boxContents.toString() + "]"); counter++; } } public static void main(String[] args) { java.util.ArrayList<Box<Integer>> listOfIntegerBoxes = new java.util.ArrayList<>(); BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes); BoxDemo.outputBoxes(listOfIntegerBoxes); } }

Question 4 of 10
★ FPSC ★ PPSC

Which of these type parameters is used for a generic methods to return and accept a number?

Question 5 of 10
★ FPSC ★ PPSC

Which of the following allows us to call generic methods as a normal method?

Question 6 of 10
★ FPSC ★ PPSC

What will be the output of the following Java program? import java.util.*; public class genericstack <E> { Stack stk = new Stack <E>(); public void push(E obj) { stk.push(obj); } public E pop() { E obj = stk.pop(); return obj; } } class Output { public static void main(String args[]) { genericstack <String> gs = new genericstack (); gs.push("Hello"); System.out.println(gs.pop()); } }

Question 7 of 10
★ FPSC ★ PPSC

Which of these type parameters is used for a generic methods to return and accept any type of object?

Question 8 of 10
★ FPSC ★ PPSC

Which of the following keywords are used for lower bounding a wild card?

Question 9 of 10
★ FPSC ★ PPSC

What is use of wildcards?

Question 10 of 10
★ FPSC ★ PPSC

Which of these types cannot be used to initiate a generic type?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →