# Inheritance and Composition: Is-a and Has-a

Two ways to build a class from another: inheritance, where an e-bike is a bike and overrides its price, and composition, where a bike has a lock it keeps as a field; saying the relationship aloud, is-a or has-a, tells you which one fits.

![Cheat sheet: Inheritance and Composition: Is-a and Has-a](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/b7a8bd25a65040069d99c7fddbdfecb1.webp)

- Category: Data Structures
- Level: Apprentice
- Tags: Composition, c-sharp, inheritance, Is-a vs Has-a, java, JavaScript, Method Overriding, OOP, python, typescript
- Author: Gregor Dzierzon
- Updated: November 17, 2026

Source: https://www.ask-codey.com/cheat-sheets/dp-inheritance-and-composition-cheat-sheet
