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.
abstract class Gauge { protected String units = "kPa"; protected final double reading; Gauge(double reading) { this.reading = reading; System.out.println("Gauge ready"); } abstract double toDisplay(); } class TireGauge extends Gauge { private int decimals = 1; TireGauge(double reading) { super(reading); System.out.println("TireGauge ready"); } double toDisplay() { return reading; } }
1.
The TireGauge field initializer sets decimals to 1.
2.
The Gauge field initializer sets units to "kPa".
3.
The TireGauge constructor begins, and its first statement super(reading) passes control to the Gauge constructor.
4.
Memory for the TireGauge object is allocated, with units, reading and decimals holding their default values.
5.
The TireGauge constructor body prints TireGauge ready.
6.
The Gauge constructor body stores the reading and prints Gauge ready.
Unlock full course notes by signing up
Which subclass declarations compile?
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.
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.