0 day streak
java / beginner
Snippet

Basic Inheritance

Inheritance allows a child class to inherit all accessible fields and methods from a parent class, promoting code reuse.

snippet.java
java
1
2
3
4
5
class Vehicle {
void move() { }
}
class Car extends Vehicle {
}
Breakdown
1
class Car extends Vehicle
The 'extends' keyword establishes that Car is a child of the Vehicle class.
2
void move() { }
A method in the parent class that will be available to all child classes.