Moving counts through a static operation

A Java ticket office uses the class below. In a fresh run, the shown statements execute inside main, with a and b referring to distinct objects. Select every correct statement about transfer and the resulting state.


Java
class TicketCounter {
    int sold = 0;
    static int total = 0;

    void sell(int amount) {
        sold = sold + amount;
        total = total + amount;
    }

    static int transfer(TicketCounter from,
                        TicketCounter to,
                        int amount) {
        from.sold = from.sold - amount;
        to.sold = to.sold + amount;
        return total;
    }
}


Java
TicketCounter a = new TicketCounter();
TicketCounter b = new TicketCounter();
a.sell(6);
b.sell(4);
int reported = TicketCounter.transfer(a, b, 2);
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 Class Attributes and Methods Questions: