Tracing a shared operation

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.


Java
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();

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Interfaces Questions: