VOOZH about

URL: https://www.geeksforgeeks.org/dart/interface-in-dart/

⇱ Interface in Dart - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Interface in Dart

Last Updated : 3 Apr, 2025

The interface in the dart provides the user with the blueprint of the class, which any class should follow if it interfaces that class, i.e., if a class inherits another, it should redefine each function present inside an interfaced class in its way. They are nothing but a set of methods defined for an object. Dart doesn't have any direct way to create an inherited class, we have to make use of the implements keyword to do so.

Syntax: 

class Interface_class_name{
...
}

class Class_name implements Interface_class_name {
...
}

Image Representation:

👁 interfaces_in_dart


Example:

Output:

Welcome to GeeksForGeeks

Note: Class should use the implements keyword, instead of extending to be able to use an interface method.


Multiple Inheritance in Dart

In Dart, multiple inheritances are achieved by the use of implements. Although, practically, dart doesn't support multiple inheritances, it supports multiple interfaces.

Syntax:

class interface_class1 {
...
}
class interface_class2 {
...
}
.
.
.
.
class interface_classN {
...
}

class class_name implements interface_class1, interface_class2, ...., interface_classN {
...
}


Example:

Output:

Howdy Geek1,
Welcome to GeeksForGeeks
Howdy Geek2,
Welcome to GeeksForGeeks
Howdy Geek3,
Welcome to GeeksForGeeks


Importance of Interface:

  • Used to achieve abstraction in Dart.
  • It is a way to achieve multiple inheritances in Dart.

Important Points

  • If a class has been implemented then all of its method and instance variable must be overridden during the interface.
  • In dart, there are no direct means to declare an interface, so a declaration of a class is itself considered as a declaration on the interface.
  • A class can extend only one class but can implement as many as you want.
Comment
Article Tags:
Article Tags:

Explore