Tracking cart-line quantities

A Java shopping program uses the class below. In a fresh run, the statements shown execute inside main in order. Complete the table after each call using exact integer numbers of units.


Java
class CartLine {
    int units = 0;
    static int added = 0;

    void add(int amount) {
        units = units + amount;
        added = added + amount;
    }
}


Java
CartLine p = new CartLine();
CartLine q = new CartLine();
p.add(4);
q.add(6);
p.add(2);
After callp.unitsq.unitsCartLine.added
p.add(4)
q.add(6)
p.add(2)

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: