O'Reilly logo

Agile Java™: Crafting Code with Test-Driven Development by Jeff Langr

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 6. Inheritance

In this lesson you will learn about:

• switch statements

• maps

• lazy initialization

• inheritance

• extending methods

• calling superclass constructors

• the principle of subcontracting

The switch Statement

In the last chapter, you coded methods in HonorsGradingStrategy and RegularGradingStrategy to return the proper GPA for a given letter grade. To do so, you used a succession of if statements. As a reminder, here is what some of the relevant code looks like (taken from HonorsGradingStrategy):

int basicGradePointsFor(Student.Grade grade) {   if (grade == Student.Grade.A) return 4;   if (grade == Student.Grade.B) return 3;   if (grade == Student.Grade.C) return 2;   if (grade == Student.Grade.D) return 1;   return 0; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required