A Java device library contains the abstract class below. Treat each table row as a separate source file in the same package, with no other errors. Enter yes or no to indicate whether each proposed subclass declaration compiles.
abstract class Device { protected Device() { } public abstract int read(); public String unit() { return "counts"; } }
Unlock full course notes by signing up
Counting the remaining implementations
A Java file-processing library has the draft declarations below. Keep CsvJob concrete and directly extending CheckedJob, and leave all earlier classes unchanged. How many additional method implementations must be declared inside CsvJob for it to compile? Give the number of implementations as an exact integer, with zero decimal places.
Tracing totals through an abstract fare class
A transit app models fares with the Java classes below. The superclass Ticket is abstract: it stores the base fare through its constructor and defines total(), which relies on a surcharge() method that only the subclasses implement.
The program then runs these statements:
Give the value returned by student.total() and the value returned by peak.total(), each in dollars to two decimal places.
Repairing a concrete class without weakening its contract
The following Java draft does not compile because LeakAlert is incomplete. Evaluate each proposed change independently, keeping Alert and its abstract text() contract unchanged and keeping LeakAlert concrete. Each change may edit LeakAlert's declaration or add one new class; LeakAlert itself must declare no methods other than those named in the change. Select every change that makes LeakAlert compile.
When the abstract superclass's constructor runs
A sensor library declares an abstract class Gauge and a concrete subclass TireGauge, as shown below. A program evaluates the expression new TireGauge(220.0). Put the initialization events for this new object in the order Java performs them.