A print shop uses the Java interface and classes below. The client statements run inside a valid method. What value does total store, in pages? Give an exact integer, with zero decimal places.
interface PageCount { int pages(); } class Report implements PageCount { public int pages() { return 14 + 5; } } class Poster implements PageCount { public int pages() { return 4; } } // Inside a method: PageCount a = new Report(); PageCount b = new Poster(); int total = 2 * a.pages() + b.pages();
Unlock full course notes by signing up
What an interface guarantees
A Java photo editor defines Saveable as shown below. Its documentation says that save() must preserve the current image data. Which statements about this design are correct? Select every correct statement.
Counting obligations across combined contracts
A monitoring application uses the Java declarations below. Each table row describes a separate planned concrete class that has no method declarations of its own yet.
For each planned class, enter the minimum number of distinct method implementations it must add to compile. Count only obligations from the displayed interfaces. Classes without a named superclass extend Object; each added method supplies one required operation.
Repairing two interface errors
A recreation-centre account starts with 20 tokens, and each pool visit costs 2 tokens. The Java program below does not compile. The client statements belong inside a valid method.
Keep VisitCost unchanged and keep pass declared as VisitCost. Which pair of edits makes the concrete class and client compile, with used equal to 8 tokens and left equal to 12 tokens? No other edits are made.
Combining competing default implementations
A Java application combines a saved display name with a current display name. The unrelated interfaces below both provide label(), so the implementing class explicitly combines their results.
VISIBILITY, FIRST, and SECOND are placeholders. Replace each with one Java keyword or interface name so that the class compiles and new CombinedName().label() returns exactly "saved/current". Preserve all other code.
Replace VISIBILITY with ________, FIRST with ________, and SECOND with ________.