GCGrowCarrer

Interfaces and Abstract Classes

Locked

Lesson 13 of 60 · OOP · Medium

Finish these first:Inheritance →Or pass the tests below to unlock it now.

1

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).
Key words (tap to learn):
2

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; }
}
3

Quick check

Before writing code: What should `new Solution.Rect(2,3).area()` return when your implementation of Interfaces and Abstract Classes is working?

4

Your challenge

2 sample tests, 1 hidden

Define interface Shape with area() and implement Rect(w, h).

Stuck? Get a hint (free)
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.

Mastery0%