• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 33 pages
Exam (elaborations)

Java OCP Part3. Generics and Collections Exam with all Correct & 100% Verified Answers |Already Graded A+

Document preview thumbnail
Preview 4 out of 33 pages

Java OCP Part3. Generics and Collections Exam with all Correct & 100% Verified Answers |Already Graded A+

Content preview

Java OCP Part3. Generics and Collections Exam with all Correct &
100% Verified Answers |Already Graded A+
1. Which of the following can
B,C.
fill in the blank to make the
When declaring a class that uses generics, you
code com-pile?
must specify a name for the formal type parameter
public class News< >
(normally T or R). Java uses the standard rules for
{} (Choose all that apply)
naming a variable or class. A question mark is not
A. ?
allowed in a variable name, making I incorrect.
B. News
While it is common practice to use a single
C. Object
uppercase letter for the type parameter, this is
D. None of them
not required. It certainly isn't a good idea to use
existing class names like the News class being
declared here or the Object class built into java.
However, this is allowed, and Option B,C is
2. Does it compile?
correct.
Integer[] numbers = { new
Inte-ger(42)}; True
Object[] objects = numbers;

3. Does it compile?
List<String> numbers =
new Ar-rayList<>(); no
List<Object> objects = We cannot assign a List<String> to a
numbers; List<Object>.

4. Set<String> set = new
Hash-Set<>();
System.out.println(set.add(" true
Spar-row")); false
System.out.println(set.add("
Spar-row"));
What will be printed?

5. List<String> birds =
new Ar-rayList<>();


, Java OCP Part3. Generics and Collections Exam with all Correct &
100% Verified Answers |Already Graded A+

[hawk]






, Java OCP Part3. Generics and Collections Exam with all Correct &
100% Verified Answers |Already Graded A+
birds.add("hawk"); Set<Rabbit> rabbits =
birds.add("hawk"); new TreeSet<>();
birds.remove("hawk"); rabbits.add(new
System.out.println(birds); Rabbit());
System.out.println(rabbi
6. List<String> birds = ts);
new Ar-rayList<>();
birds.add("hawk");
birds.add("hawk");
birds.remove(100);
System.out.println(birds);

7. List<String> birds =
new Ar-rayList<>();
birds.add("hawk");
birds.add("hawk");
System.out.println(birds.
con-tains(1));

8. NavigableSet<Integer> set
= new TreeSet<>();
for (int i = 1; i <= 20; i++)
set.add(i);
System.out.println(set.lower(1
0));
System.out.println(set.high-
er(20));
System.out.println(set.floor(10
));
System.out.println(set.ceiling(
20));

9. static class Rabbit{ }


, Java OCP Part3. Generics and Collections Exam with all Correct &
100% Verified Answers |Already Graded A+




IndexOutOfBoundsException




false (signature: boolean contains(Object object))




9
null
10
20




B.
Compile but ClassCastException in runtime. Rabbit
does not implement Comparable. TreeSet is not
able to sort it into the proper position in the set.

Document information

Uploaded on
August 22, 2026
Number of pages
33
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$21.99

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

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Studyclub
3.6
(14)
Sold
68
Followers
1
Items
13214
Last sold
4 days ago



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