About Question enthuware.ocpjp.v7.2.1127 :

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

Moderator: admin

Post Reply
rtteal
Posts: 1
Joined: Sun Aug 31, 2014 3:02 pm
Contact:

About Question enthuware.ocpjp.v7.2.1127 :

Post by rtteal »

Technically, this code will not compile:

/tmp> javac temp.java
temp.java:1: error: class, interface, or enum expected
Deque<Integer> d =new ArrayDeque<>();
^
temp.java:2: error: class, interface, or enum expected
d.add(1);
^
temp.java:3: error: class, interface, or enum expected
d.add(2);
^
temp.java:4: error: class, interface, or enum expected
d.addFirst(3);
^
temp.java:5: error: class, interface, or enum expected
System.out.println(d.pollLast());
^
temp.java:6: error: class, interface, or enum expected
System.out.println(d.pollLast());
^
temp.java:7: error: class, interface, or enum expected
System.out.println(d.pollLast());
^
7 errors

The questions should say, "assume this is in a method with proper imports" like the others...

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

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

Post by admin »

Well, it does not have a class declaration or even a method declaration. There is no main method, so it can't run either.
But the question is asking only about the code snippet that is shown assuming that everything else that is not shown is fine. This is a standard practice in the real exam as well.
The statement regarding assumption appears only when there is a reasonable doubt about something that impacts the answer. Here, there is no such doubt because this is obviously a partial listing.

jackdaniels
Posts: 10
Joined: Sun Feb 04, 2018 7:05 am
Contact:

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

Post by jackdaniels »

Why are the below methods Queue specific when they are not visible in the docs?
https://docs.oracle.com/en/java/javase/ ... Queue.html

pollFirst()/pollLast()
offerFirst(e)/offerLast(e)
addFirst(e)/addLast(e

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

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

Post by admin »

They are not queue specific. They are defined in Deque. poll is queue specific, which is what the explanation also notes. The explanation is only giving you a memory aid to remember how pollFirst and pollLast work using their relation to poll. It is connected with the earlier part of the explanation.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests