About Question enthuware.ocpjp.v7.2.1292 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
boyonsea
Posts: 16
Joined: Fri Sep 04, 2015 5:06 pm
Contact:

About Question enthuware.ocpjp.v7.2.1292 :

Post by boyonsea »

Why cant "Queue container = new PriorityQueue();" be used?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1292 :

Post by admin »

The first sentence of the explanation explains exactly what you are asking. I am quoting it here for your convenience,
Since the return type of getRequestToProcess() method is Request, and the return statement does not have a cast, it means that container must be a typed generic collection that returns Request objects only.

unvector
Posts: 18
Joined: Sun Jun 21, 2015 2:56 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1292 :

Post by unvector »

If there would be such answer:
Queue<Request> container = new PriorityQueue<Request>();
Would it be correct? it would compile, but PriorityQueue would throw exception while adding an element to nonempty queue.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1292 :

Post by admin »

Yes, it would have been valid. Yes, it is possible for an exception to be thrown if the code is not used correctly but that is irrelevant for the question.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests