Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to deal with exam answers with "at least one/once"?

 
Ranch Hand
Posts: 229
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Bartender
Posts: 4738
183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did they give an explanation?
 
Marshal
Posts: 74683
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At least 4 times means 4 times, or 5, 6, 7, 8...
 
Piet Souris
Bartender
Posts: 4738
183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, the question was: when is "exactly 1" "ar least one". OP gave two examples where rhe answers were not consistent.


Edir: it took me quite some time to figure out why, in eample 1, "Swim!" was only printed once. Never knew that lock.lock(); lock.trylock();  requires two unlocks.
 
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At least one means one or more.

In the second example you cited, the question is asking about a rule. And "exactly one" meets the rule. Not "one or more"
 
Do not threaten THIS beaver! Not even with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic