A storage dashboard records available space when its monitor is constructed, then requests a fresh reading. Trace this Java program:
class StorageMonitor { private int storedAvailableMiB; public StorageMonitor() { storedAvailableMiB = availableMiB(); } public int availableMiB() { return 128; } public int storedAvailableMiB() { return storedAvailableMiB; } } class ReservedStorage extends StorageMonitor { private int reservedMiB = 24; @Override public int availableMiB() { return 128 - reservedMiB; } } class Demo { public static void main(String[] args) { StorageMonitor monitor = new ReservedStorage(); System.out.println(monitor.storedAvailableMiB()); System.out.println(monitor.availableMiB()); } }
Java gives instance int fields the default value 0 before constructor code runs. A subclass's field initializer runs after its superclass constructor returns.
Report the stored available space printed by the first statement and the fresh available space printed by the second statement. Give both in MiB, as exact integers with zero decimal places.
Unlock full course notes by signing up
Tracing inherited implementations
A delivery scheduler estimates processing time in seconds with the Java classes below. Complete the table with the exact integer returned by each independent call.
Checking changes to an override
A monitoring application contains the following Java classes. Consider each proposed change independently, starting from this original code. Which statements are correct? Select all that apply.
Checking an override's exception declaration
A Java file-export component declares a method with a checked exception:
Each table row proposes a method declaration in a separate direct subclass of Exporter. Every candidate has an empty body and an @Override annotation. All named exception classes are correctly imported.
Use these relationships: FileNotFoundException extends IOException; Exception is a superclass of IOException; SQLException is not a subclass of IOException; and IllegalStateException is unchecked.
Following an overridden helper through super
A game calculates an award using the Java classes below. The helper call bonus() is an ordinary instance-method call on the current object. What does the final statement print?