Page 1 of 1

About Question enthuware.ocpjp.v7.2.1127 :

Posted: Tue Sep 02, 2014 9:43 pm
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...

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

Posted: Tue Sep 02, 2014 9:53 pm
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.

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

Posted: Sun Feb 16, 2020 11:45 am
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

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

Posted: Sun Feb 16, 2020 10:40 pm
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.