I have come across questions in the Sybex online
test bank which uses "at least one/once" in the answer choices. If the correct answer is exactly one, then is an answer with "at least one" correct?
Consider the two questions below.
In the first question, "Swim!" will print exactly once (no more and no fewer), and answer A is a correct choice.
What is the result of executing the following program? (Choose all that apply.)
import java.util.concurrent.*;
import java.util.concurrent.locks.*;
public class BeachManager {
private Lock lock = new ReentrantLock();
public void goSwimming() {
lock.lock(); // y1
if (lock.tryLock()) { // y2
System.out.println("Swim!");
}
lock.unlock();
}
public static void main(String[] args) {
ExecutorService service = null;
try {
BeachManager b = new BeachManager();
service = Executors.newFixedThreadPool(2);
for (int i = 0; i < 2; i++)
<br /> service.submit(() -> b.goSwimming());
} finally {
if (service != null) service.shutdown();
}
System.out.print("Tasks Complete");
}
}
A. It prints Swim! at least once.
B. It prints Swim! exactly twice.
C. It prints Tasks Complete.
D. It hangs indefinitely at runtime.
E. The code will not compile because of line y1.
F. The code will not compile because of line y2.
G. It throws an exception at runtime.
In the second question, there can be exactly one abstract method in a functional interface (no more and no fewer), and yet answer E is an incorrect answer.
Actually this answer should be correct since abstract methods from Objects do not count. So a functional interface will have one or more abstract methods. But let's assume that answer E is not counting the abstract methods from Objects, and that it must have exactly one abstract method.
Which statements about functional interfaces are true? (Choose all that apply.)
A. A functional interface can contain default and private methods.
B. A functional interface can be defined by a class or interface.
C. Abstract methods with signatures that are contained in public methods of java.lang.Object do not count toward the abstract method count for a functional interface.
D. A functional interface cannot contain static or private static methods.
E. A functional interface contains at least one abstract method.
F. A functional interface must be marked with the @FunctionalInterface annotation.