Inheritance
LockedLesson 12 of 60 · OOP · Medium
Finish these first:Constructors and Encapsulation →Or pass the tests below to unlock it now.
The big idea
extends inherits fields/methods; super(...) calls the parent constructor; @Override marks overrides. Java has single class inheritance.
Think of it like this: Think of a Class as a cookie cutter (the blueprint) and each Object as an individual cookie stamped from it — each cookie can have its own frosting (state) while sharing the same shape (methods).
Read the lesson
extends inherits fields/methods; super(...) calls the parent constructor; @Override marks overrides. Java has single class inheritance.
class Animal { String sound() { return "..."; } }
class Dog extends Animal {
@Override String sound() { return "Woof"; }
}
Quick check
Before writing code: What should `new Solution.Square(3).area()` return when your implementation of Inheritance is working?
Your challenge
Create Shape.area() (returns 0) and Square(int side) overriding it.
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.inheritance (85% overlap). Python allows multiple inheritance; Java has single class inheritance + interfaces.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Inheritance.