Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Java Generics Exam Paper 2026/2027 – 53 Questions on Classes, Methods & Wildcards with Answers Exam

Rating
-
Sold
-
Pages
18
Grade
A+
Uploaded on
14-03-2026
Written in
2025/2026

Java Generics Exam Paper 2026/2027 – 53 Questions on Classes, Methods & Wildcards with Answers Exam

Institution
3x@m
Course
3x@m

Content preview

Java Generics Exam Paper 2026/2027 – 53
Questions on Classes, Methods & Wildcards
with Answers
EXAM




Section A: Multiple Choice (30 Questions - 30 Marks)

Circle the correct answer for each question.

1. What is the primary purpose of Java Generics?
a) To simplify the syntax of collections.
b) To enable types (classes and interfaces) to be parameters when defining
classes, interfaces, and methods.
c) To improve the runtime performance of code by avoiding method calls.
d) To replace the need for object-oriented inheritance.
2. Which of the following is a benefit of using generics?
a) Stronger type checks at compile time.
b) Elimination of explicit casts.
c) Enabling programmers to implement generic algorithms.
d) All of the above.
3. Consider the class: class Box<T> { ... }. What is T called?
a) A type parameter
b) A type argument
c) A wildcard
d) An unbounded type
4. Given Box<Integer> intBox = new Box<>();, what is Integer in this context?
a) A type parameter
b) A type argument

, c) A raw type
d) A bounded type parameter
5. What is a "raw type" in Java Generics?
a) A generic class without its type parameter, e.g., Box box = new Box();
b) A primitive type used as a type argument, e.g., Box<int>
c) A generic type with multiple parameters.
d) A type that has been erased by the compiler.
6. Which statement about raw types is true?
a) They are recommended for use in new code for simplicity.
b) They are only allowed for backward compatibility with pre-Java 5 code.
c) They provide the same type safety as parameterized types.
d) They cannot be assigned a value from a parameterized type.
7. What will be the result of compiling and running the following code?
Box rawBox = new Box();

rawBox.setContent("Hello");

String content = (String) rawBox.getContent();

a) Compilation error on the first line.
b) Compilation error on the third line because of an unchecked cast.
c) Compiles with an unchecked warning, runs without error.
d) Compiles without warning, but throws a ClassCastException at runtime.
8. How do you define a generic method that accepts an array of any type and prints
its elements?
a) public static void printArray(Object[] array) { ... }
b) public static <T> void printArray(T[] array) { ... }
c) public static void printArray(T[] array) { ... }
d) public static <?> void printArray(?[] array) { ... }
9. In the generic method public static <T> T getMiddle(T... a) { return
a[a.length/2]; }, what is the syntax <T> before the return type called?
a) The type parameter list
b) The return type declaration

, c) The method signature
d) The type argument list
10. What is the purpose of a bounded type parameter, such as <T extends Number>?
a) It restricts T to only the Number class.
b) It allows the type argument to be Number or any of its subclasses.
c) It allows the type argument to be any class that implements Number.
d) It improves the performance of generic algorithms.
11. Consider <T extends Comparable<T>>. What does this signify?
a) T must implement the Comparable interface and can only be compared to itself.
b) T must extend the class Comparable.
c) T must be comparable to any type.
d) T must be a subclass of Comparable.
12. What does the unbounded wildcard ? represent?
a) Any type, and you can safely read from and add to a collection of it.
b) An unknown type. You can only read objects as instances of Object from a
structure, and you cannot add elements (except null).
c) The same as <? extends Object>.
d) Any type, and it's the preferred way to declare a variable for any generic class.
13. Which wildcard should you use to define a method that accepts a collection of
objects of any type that is a subclass of Number, for read-only access?
a) Collection<Number>
b) Collection<? super Number>
c) Collection<? extends Number>
d) Collection<T extends Number>
14. Which wildcard should you use to define a method that accepts a collection of
objects of any type that is a superclass of Integer, for write-only access?
a) Collection<Integer>
b) Collection<? super Integer>
c) Collection<? extends Integer>
d) Collection<Integer super ?>

Written for

Institution
3x@m
Course
3x@m

Document information

Uploaded on
March 14, 2026
Number of pages
18
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$23.59
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
marynjeriwanjiku

Get to know the seller

Seller avatar
marynjeriwanjiku chamberlain college of nursing
Follow You need to be logged in order to follow users or courses
Sold
2
Member since
4 months
Number of followers
0
Documents
381
Last sold
2 days ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions