Interfaces and Abstract Classes
LockedLesson 13 of 60 · OOP · Medium
Finish these first:Inheritance →Or pass the tests below to unlock it now.
The big idea
Interfaces define contracts (and can have default methods); abstract classes share state and partial implementation. A class may implement many interfaces.
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
Interfaces define contracts (and can have default methods); abstract classes share state and partial implementation. A class may implement many interfaces.
interface Shape { double area(); }
record Circle(double r) implements Shape {
public double area() { return Math.PI * r * r; }
}
Quick check
Before writing code: What should `new Solution.Rect(2,3).area()` return when your implementation of Interfaces and Abstract Classes is working?
Your challenge
Define interface Shape with area() and implement Rect(w, h).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
See how Java compares side-by-side with Python.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Interfaces and Abstract Classes.
Learn this first
- InheritanceNot yet