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.
class Lamp(var hours: Int) val original = List(new Lamp(6), new Lamp(3)) val expanded = original :+ new Lamp(2) original.head.hours = 8
The first Lamp reached through expanded still has 6 hours.
The list referenced by expanded still has exactly 2 elements.
The list referenced by original still has exactly 2 elements.
The first Lamp reached through expanded now has 8 hours.
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.
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.
Repack crates through an array parameter
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:
The following fragment runs inside another method: