A bottling workshop uses Java arrays of Crate objects. Each object has a mutable integer field bottles; new Crate(n) creates a distinct object whose field equals n.
The workshop defines this method:
static Crate[] repack(Crate[] crates) { crates[0].bottles += 2; crates[1] = new Crate(9); crates = new Crate[] { new Crate(14), crates[0] }; crates[0].bottles -= 3; return crates; }
The following fragment runs inside another method:
Crate[] original = { new Crate(4), new Crate(6) }; Crate[] repacked = repack(original); repacked[1].bottles += 4;
After the fragment finishes, find the sum of the bottles fields accessed through each array: the original total and the repacked total. Give both answers as exact integer numbers of bottles. Count each array position once when calculating its total.
Unlock full course notes by signing up
Copy the list, then change its contents
An inventory application executes the Java fragment below. The ArrayList constructor used for review creates a separate list containing the element references from cart. Find the final sum of units across cart and the final sum across review. Report both totals in units as exact integers.
An immutable list containing mutable lamps
A lighting application executes this Scala 3 code. The head operation accesses the first element, and the :+ operation produces a list with an appended element. Which statements are true after all statements execute? Select every true statement.
Find the first matching ticket
A Java ticket system uses the following method to search an array. Each Ticket has an integer field code, and its constructor sets that field to the supplied value.
The array supplied to every call is initialized as follows:
Complete the table for three independent calls. Count a code comparison only when items[i].code == target is evaluated. Java evaluates the right side of && only when its left side is true. Give every answer as an exact integer.
Visit a shared box twice
A Java warehouse program processes an array whose first and last positions refer to the same Box. Both loops visit positions from index zero to index two. What final value is stored in total? Answer in units as an exact integer.