Dart : Interface Class

Dart : Interface Class

·

1 min read

Interface Class

  • To define an interface, use the interface modifier. Libraries outside of the
    interface's own defining library can implement the interface, but not extend it.

  • When one of the class's instance methods calls another instance method on
    this , it will always invoke a known implementation of the method from the same
    library.

  • Other libraries can't override methods that the interface class's own methods
    might later call in unexpected ways.

interface class Vehicle {
  void moveForward(int meters) {
    // ...
  }
}
abstract class Interface {

    void method1();
    void method2();

}

class MyClass implements Interface {

    @override
    void mehod1() {

        print("Methods 1");

    }

    @override
    void method2(){

        print("Methods 2");

    }
}

    void main()
    {

        var obj = MyClass();
        obj.method1();
        obj.method2();

    }
Methods 1
Methods 2

Exited.