VOOZH about

URL: https://www.geeksforgeeks.org/dart/dart-concept-of-inheritance/

⇱ Dart - Concept of Inheritance - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Dart - Concept of Inheritance

Last Updated : 12 Jul, 2025

In Dart, one class can inherit another class, i.e. dart can create a new class from an existing class. We make use of extend keyword to do so.

Terminology:

  • Parent Class: It is the class whose properties are inherited by the child class. It is also known as a base class or super class.
  • Child Class: It is the class that inherits the properties of the other classes. It is also known as a derived class or sub class.

Example:

// parent class or base class or super class
class parent_class{
...
}

// child class or derived class or sub class
class child_class extends parent_class{
...
}

Types of Inheritance

  1. Single Inheritance: This inheritance occurs when a class inherits a single-parent class.
  2. Multi-Level Inheritance: This inheritance occurs when a class inherits from another class, which is already derived from a parent class..
  3. Hierarchical Inheritance: Multiple child classes inherit from a common parent class.
  4. Multiple Inheritance: This inheritance occurs when a class inherits more than one parent class. Dart doesn't support this.

Important Points

  • Child classes inherit all properties and methods except constructors of the parent class.
  • Like Java, Dart also doesn't support multiple inheritance.

1. Single Inheritance

In single inheritance, a sub-class is derived from only one super class. It inherits the properties and behavior of a single-parent class. Sometimes, it is also known as simple inheritance. In the below figure, ‘A’ is a parent class, and ‘B’ is a child class. Class ‘B’ inherits all the properties of class ‘A’.

👁 Image

Program :

Output:

Welcome to gfg!!
You are inside output function.


2. Multilevel Inheritance

In Multilevel Inheritance, a derived class will be inheriting a base class, and as well as the derived class also acts as the base class for other classes. In the below image, class A serves as a base class for the derived class B, which in turn serves as a base class for the derived class C.

👁 Image

Program :

Output:

Welcome to gfg!!
You are inside the output function of Gfg class.
Welcome to gfg!!
You are inside the output function of GfgChild1 class.


3. Hierarchical inheritance

In Hierarchical Inheritance, one class serves as a superclass (base class) for more than one subclass. In the image below, class A serves as a base class for the derived classes B, C, and D.

👁 Image

Program :

Output:

Welcome to gfg!!
You are inside output function of Gfg class.
Welcome to gfg!!
You are inside output function of Gfg class.
Welcome to gfg!!
You are inside output function of Gfg class.


4. Multiple Inheritance (Not Supported in Dart)

Dart does not support multiple inheritance directly. This means a class cannot inherit from more than one parent class. However, Dart provides mixins as an alternative to achieve similar functionality.

👁 multiple_inheritance

Program:


Output :

This is class A.
This is class B.
This is class C.

Conclusion

Inheritance in Dart allows for code reuse and establishes a structured class hierarchy through the use of the extends keyword. Dart supports single inheritance, multilevel inheritance, and hierarchical inheritance; however, it does not permit multiple inheritance to reduce complexity. Instead, Dart offers mixins as a method for sharing code across multiple classes. Understanding inheritance is crucial for building scalable and maintainable applications.

Comment
Article Tags:
Article Tags:

Explore