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?


Java
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;
    }
}


Java
Score score = new EventScore();
System.out.println(score.points(3));
Choose an answer

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 Method Overriding Questions: