Sitemap
Dart Tutorials

Dart Tutorials for beginners and advanced programmers

Inheritance in Dart

2 min readMar 27, 2025

--

Inheritance is a fundamental concept in object-oriented programming (OOP) that allows one class to inherit properties and methods from another class. In Dart, the extends keyword is used to achieve inheritance.

Press enter or click to view image in full size

Read Medium Story for Free 👇

Basic Inheritance

A child class can inherit properties and methods from a parent class using extends.

class Animal {
void makeSound() {
print("Animal makes a sound");
}
}

class Dog extends Animal {
void bark() {
print("Dog barks");
}
}

void main() {
var dog = Dog();
dog.makeSound(); // Inherited method
dog.bark(); // Dog-specific method
}

Overriding Methods

A subclass can override a parent class method using the @override annotation.

class Animal {
void makeSound() {
print("Animal makes a sound");
}
}

class Cat extends Animal {
@override
void makeSound() {
print("Cat meows");
}
}

void main() {
var cat = Cat();
cat.makeSound(); // Output: Cat meows
}

--

--

Usama Sarwar
Usama Sarwar

Written by Usama Sarwar

Helping founders turn ideas into market-ready web and mobile apps within 30 days using Google’s Flutter & Next.js without juggling multiple teams.

Dart Tutorials
Dart Tutorials

Published in Dart Tutorials

Dart Tutorials for beginners and advanced programmers