Repairing two interface errors

A recreation-centre account starts with 20 tokens, and each pool visit costs 2 tokens. The Java program below does not compile. The client statements belong inside a valid method.


Keep VisitCost unchanged and keep pass declared as VisitCost. Which pair of edits makes the concrete class and client compile, with used equal to 8 tokens and left equal to 12 tokens? No other edits are made.


Java
interface VisitCost {
    int tokens(int visits);
}

class Pool implements VisitCost {
    public int tokens(long visits) {
        return (int) (2 * visits);
    }

    public int remaining() {
        return 20;
    }
}

// Inside a method:
VisitCost pass = new Pool();
int used = pass.tokens(4);
int left = pass.remaining();
Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Interfaces Questions: