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?
class Score { public int bonus() { return 2; } public int points(int hits) { return bonus() + 4 * hits; } } class EventScore extends Score { @Override public int bonus() { return 7; } @Override public int points(int hits) { return super.points(hits) + 5; } }
Score score = new EventScore(); System.out.println(score.points(3));
24
19
29
12
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.
Calling an override before field initialization
A storage dashboard records available space when its monitor is constructed, then requests a fresh reading. Trace this Java program:
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.