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; ...

Get Agile Java™: Crafting Code with Test-Driven Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.