A scheduler estimates processing time in integer ticks using the Java code below. The client statements run inside a method, and each iteration calls ticks() exactly once. Find the total processing ticks and the number of calls that execute RenderTask.ticks(). Give both answers as exact integers.
class Task { int ticks() { return 3; } } class CachedTask extends Task { int ticks() { return 1; } } class RenderTask extends Task { int ticks() { return 7; } }
Task[] queue = { new CachedTask(), new RenderTask(), new Task(), new CachedTask(), new RenderTask() }; int total = 0; for (Task task : queue) { total += task.ticks(); }
Unlock full course notes by signing up
Available calls and selected behaviour
A dashboard uses the Java classes below, followed by the client declaration inside a method. Which statements about permitted calls and runtime behaviour are true? Select all that apply.
Follow a call inside an inherited method
A device simulator models packet sizes with the following Java classes. A frame contains two copies of its packet's payload plus three bytes of framing information. Every size returned by a method is measured in bytes.
Complete the table with the exact integer returned by each call. All three variables are declared as Packet, and neither subclass declares its own frameBytes method.
Track dispatch after reassignment
A Java worker program uses the classes and client statements below. Each new object begins with its own units field equal to 2. Track both the selected method and the changing object state. What is the final value of total? Give an exact integer.
The following statements run inside a method:
Resolve nested job objects
A maintenance simulator uses Java objects to predict job durations in seconds. A Task returns its stored duration. A Parallel object models two jobs starting together and adds four seconds of overhead after both finish. A Repeat object models consecutive repetitions of its child job.
The following code fully specifies the model. Assume durations are exact and there are no other delays.
Math.max returns the larger of its two arguments. The diagram shows the objects created by the final two statements. Each non-root box begins with the name of the stored reference pointing to that object.