![]() |
VOOZH | about |
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:
Example:
Output:
Welcome to GeeksForGeeksNote: Class should use the implements keyword, instead of extending to be able to use an interface method.
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: