exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 61 discussion

Actual exam question from Oracle's 1z0-819
Question #: 61
Topic #: 1
[All 1z0-819 Questions]

Given:



and



and



and



What needs to change to make these classes compile and still handle all types of Interface Worker?

  • A. Replace Line 3 with public void addProcess (Worker w) {.
  • B. Replace Line 1 with public class Main extends Thread {.
  • C. Replace Line 2 with private List processes = new ArrayList<>();.
  • D. Replace Line 3 with public void addProcess(T w) {.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ASPushkin
6 months, 1 week ago
Selected Answer: D
A. FAILED generic types is invariant public class Main <T extends Worker > extends Thread { private List <T> processes = new ArrayList <> (); bounded type parameter <T extends Worker> means that type T is restricted by an upper bound expected to be a Worker or one of its subtypes. There are few of options if you would think about subtypes of Worker: HardWorker, Cheater, etc. That mean that your List<T> at runtime might appear to be a List<Cheater> and since behavior of generic types is invariant we would not be able to add anything that is not of type Cheater into such list (no Worker, no HardWorker). Therefore, compiler would disallow to add an HardWorker into a List<T>, where T can be anything that extends Worker (or the Worker itself), because it can't be sure that it's type-safe.
upvoted 1 times
...
mendjijet
12 months ago
Selected Answer: D
Tested D is ok
upvoted 1 times
...
d7bb0b2
1 year ago
Selected Answer: D
d is ok
upvoted 1 times
...
Omnisumem
1 year, 4 months ago
Selected Answer: D
Tested: D.
upvoted 1 times
...
tmuralimanohar
1 year, 7 months ago
Answer: D
upvoted 1 times
...
Stavok
1 year, 8 months ago
Selected Answer: D
D is correct replace line 3 with public void addProcess(T w) {
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago