A booking program should initialize a local seat count from the class's stored count, allowing for six unavailable seats. In this code, Hall.seats explicitly accesses the field declared in Hall.
class Hall { static int seats = 90; static void prepare() { int seats = seats - 6; System.out.println(seats); } }
Complete the diagnosis and repair. For the first gap, choose compilation or execution. For the second gap, choose local variable or class field. For the final gap, enter the field access using the class name, with no spaces.
The original program is rejected during because the right-hand seats in the local declaration refers to the before it has received a value. Keeping the local variable's name unchanged, replace only that right-hand seats with .
Unlock full course notes by signing up
Track one count through separate blocks
A food bank tracks packed boxes using the following fragment inside a Java method. Find the number printed by the first print statement and the number printed by the second. Enter both counts in boxes as exact integers.
Put dependent declarations in a legal order
A packing program calculates how many boxes it can fill after reserving some items. Arrange these four Java statements in the only order that compiles when they appear consecutively inside the same method block. None of these variable names is declared elsewhere, and you may not change any statement.
Separate the desk count from the class count
A parcel desk uses the following Java class. The field named parcels belongs to the class; ParcelDesk.parcels explicitly accesses it. Assume report() is called once, with the field initially holding its declared value.
Enter the three printed counts: the saved starting count, the final local count, and the final field count. Give each as an exact integer number of parcels.
Decide when reusing a local name is legal
A shop program contains the following fragment inside a Java method, with no other declarations using these names. Which statements about the fragment or the proposed changes are true? Consider each proposed change independently. Select all that apply.