Most programming tutorials explain inheritance with animals. A Dog is a Mammal. A Mammal is an Animal. It works, but it does not match what you actually build at work. You will not write a GoldenRetriever class anytime soon.

Here is what you will actually use inheritance for. You want to write a piece of logic once and reuse it in multiple classes. You want a general "base" class that handles the boring work, and specific "child" classes that only add what makes them different.

That is inheritance in practice. One class extends another and inherits its fields and methods.

The Parent and Child Idea

Imagine you run a small e-commerce site in Bangladesh. You sell products from multiple categories - electronics, clothing, groceries. Every product has a name, a price, and a seller. But an electronic item has a warranty period, while a grocery item has an expiry date.