Total a mixed processing queue

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.


Java
class Task {
    int ticks() {
        return 3;
    }
}

class CachedTask extends Task {
    int ticks() {
        return 1;
    }
}

class RenderTask extends Task {
    int ticks() {
        return 7;
    }
}


Java
Task[] queue = {
    new CachedTask(),
    new RenderTask(),
    new Task(),
    new CachedTask(),
    new RenderTask()
};

int total = 0;
for (Task task : queue) {
    total += task.ticks();
}
Your answers

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 Polymorphism Questions: