If you want to go deeper than free articles allow, I publish premium content on Gumroad — structured guides, deep-dives, and reference material built for working engineers.
Why Children Don’t Start from Zero
Every human being inherits something.
Eye colour from a parent. A family name passed down for generations. A way of laughing that skips a generation and reappears in a grandchild.
Nobody questions this.
We accept, instinctively, that certain traits, behaviours, and characteristics flow from one generation to the next — and that the child does not have to build everything from scratch.
Inheritance in programming is built on exactly this idea.
What Does the Word Actually Mean?
The word inherit comes from the Latin hereditare — meaning to make someone an heir.
An heir is someone who receives what belonged to another.
Not by creating it. Not by earning it. By being part of a lineage.
In biology, an offspring inherits the genetic blueprint of its parents. It does not reinvent breathing, eating, or movement. Those come with the territory.
It only adds what makes it unique.
That is inheritance.
A Real-World Analogy: The Family Tree
Think about a family.
A parent has certain characteristics:
Two eyes
A heartbeat
The ability to breathe
A name
When a child is born, they do not start from nothing.
They automatically inherit:
Two eyes
A heartbeat
The ability to breathe
The family name
The child does not define these things. They exist because the parent exists.
But the child can also have something the parent does not:
A different hair colour
A skill the parent never developed
A personality trait that is entirely their own
The child extends the parent.
Same foundation. New additions on top.
This is exactly what inheritance does in Object-Oriented Programming.
Support My Work
Everything I publish here is free. Always will be.
If you’ve found value in any of it — the threading series, the system design breakdowns, the DSA patterns — you can buy me a coffee via PayPal:
Why Inheritance Became Necessary in Software
Early programs were small.
One class, one file, a handful of methods. If something needed to be changed, you changed it in one place.
As software grew, a serious problem appeared.
Imagine you are building a program that models different animals.
You create a Dog:
class Dog {
String name;
void eat() {
System.out.println("Dog is eating");
}
void sleep() {
System.out.println("Dog is sleeping");
}
void bark() {
System.out.println("Dog is barking");
}
}
Then you create a Cat:
class Cat {
String name;
void eat() {
System.out.println("Cat is eating");
}
void sleep() {
System.out.println("Cat is sleeping");
}
void meow() {
System.out.println("Cat is meowing");
}
}
Look carefully.
eat() is written twice. sleep() is written twice. name is declared twice.
Now imagine you have 20 animals.
Every time eat() changes, you update it 20 times. Every time you find a bug in sleep(), you fix it 20 times.
This is called code duplication — and it is one of the most dangerous things in large software.
Inheritance was introduced to solve exactly this.
The Core Philosophy: IS-A Relationship
Before using inheritance, ask yourself one question:
Is this class truly a type of that class?
A Dog IS-A Animal.
A Cat IS-A Animal.
A Car IS-A Vehicle.
This is called the IS-A relationship.
Inheritance should only be used when one class is genuinely a specialised version of another.
If you use inheritance just to share a few methods, you are using it wrong.
The IS-A test is your guard.
If the sentence does not make sense — do not inherit.
Inheritance in Java (Conceptual View)
In Java, inheritance is expressed using the extends keyword.
A child class extends a parent class.
The child automatically receives everything the parent has — fields and methods — and is free to add its own or change what it inherited.
The parent class is often called the superclass. The child class is often called the subclass.
One parent can have many children. Each child gets the full foundation. Each child builds its own identity on top.
Applying Inheritance: One Foundation, Many Animals
Step 1: Define what all animals share — the parent class.
class Animal {
String name;
void eat() {
System.out.println(name + " is eating");
}
void sleep() {
System.out.println(name + " is sleeping");
}
}
eat() and sleep() are written once. Every animal that inherits from Animal gets them automatically.
Step 2: Create specific animals that extend Animal.
class Dog extends Animal {
void bark() {
System.out.println(name + " is barking");
}
}class Cat extends Animal {
void meow() {
System.out.println(name + " is meowing");
}
}Dog adds only what makes a Dog unique. Cat adds only what makes a Cat unique.
The shared behaviour lives in one place — the parent.
Step 3: See it in action.
Dog dog = new Dog();
dog.name = "Bruno";
dog.eat(); // inherited from Animal
dog.sleep(); // inherited from Animal
dog.bark(); // Dog's own method
Cat cat = new Cat();
cat.name = "Whiskers";
cat.eat(); // inherited from Animal
cat.meow(); // Cat's own method
Now if eat() needs to change, you change it once in Animal. Every subclass gets the fix automatically.
When the Child Wants to Do Things Differently: Method Overriding
Sometimes a child inherits a behaviour from the parent but needs to do it differently.
A Dog eats differently than a Fish. The act of eating is the same concept — the execution is different.
This is called method overriding.
class Animal {
void eat() {
System.out.println("Animal is eating");
}
}
class Dog extends Animal {
@Override
void eat() {
System.out.println("Dog is eating kibble");
}
}
class Fish extends Animal {
@Override
void eat() {
System.out.println("Fish is eating flakes");
}
}
The parent defines the contract — every animal eats. The child defines the detail — how it eats.
@Override tells Java explicitly: this method is replacing the parent’s version.
What This Example Teaches
Shared behaviour lives in the parent — written once, used everywhere
Subclasses inherit automatically — no duplication
Each subclass adds only what is unique to it
Method overriding lets a child specialise without breaking the contract
A change in the parent propagates to all children
One Line to Remember
Inheritance is not about sharing code — it is about sharing identity.
If this helped, I wrote a full book on Object-Oriented Programming — not the textbook version, the one that actually explains why these patterns exist and when to use them.
Grab it!
Let’s Stay Connected
If you found this helpful, stay connected — Through Level Up Your Programming with Nitin, I share guides, insights, and live coding sessions to help you grow as a developer.
Let’s keep learning together!
Feel free to like, comment, or share your thoughts below — I’d love to hear how your Java journey is going.
— Nitin Hashnode | Substack | LinkedIn | Youtube | Instagram | GIT | Topmate
Struggling with interviews despite studying?
Most engineers know the concepts. They lose offers on gaps they can’t see themselves. I offer 1:1 mock interviews and guidance sessions — real simulation, honest feedback, clear next steps.
Book a session with me






