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.
D is correct replace line 3 with public void addProcess(T w) {
upvoted 1 times
...
Log in to ExamTopics
Sign in:
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.
ASPushkin
6 months, 1 week agomendjijet
12 months agod7bb0b2
1 year agoOmnisumem
1 year, 4 months agotmuralimanohar
1 year, 7 months agoStavok
1 year, 8 months ago