GCGrowCarrer

Inheritance

Locked

Lesson 12 of 60 · OOP · Medium

Finish these first:Constructors and Encapsulation →Or pass the tests below to unlock it now.

1

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

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

Quick check

Before writing code: What should `new Solution.Square(3).area()` return when your implementation of Inheritance is working?

4

Your challenge

2 sample tests, 1 hidden

Create Shape.area() (returns 0) and Square(int side) overriding it.

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

Mastery0%