CS core subjects

Stage 2 · Lesson 4 of 8

Polymorphism

Object-oriented programming and design

means one call works on many types, and each type responds in its own way. Picture a checkout that calls pay() on a card, a wallet or a bank transfer. It needs no if statement for each kind, because each class supplies its own pay.

This removes long that check a type code. It also lets you add a new kind of payment without editing old code. Learn two related words.

Overriding is when a subclass replaces a parent's method, and the right version is picked while the program runs. is when several methods share a name but take different parameters, and the choice is made when the code compiles.

Common trapconfusing the two in exams and in code, or writing if type == ... chains that polymorphism was meant to replace.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking SOLID Design Principles

    Design Gurus · Beginner · $50 one-time

    Each SOLID principle with a broken example and its fix, at a beginner-friendly pace

  • CourseFree
    Java Programming MOOC

    University of Helsinki · Beginner

    Free, exercise-heavy course whose second half is a thorough, tested introduction to OOP

Keep handy

Also worth your time

Mark this stage as not done?