Dart : base class

Dart : base class

·

1 min read

Base Class

  • To enforce inheritance of a class or mixin's implementation, use the base modifier. A base class disallows implementation outside of its own library. This guarantees:

  • The base class constructor is called whenever an instance of a subtype of the class is created.

  • All implemented private members exist in subtypes.

  • A new implemented member in a base class does not break subtypes, since all subtypes inherit the new member.

  • This is true unless the subtype already declares a member with the same name and an incompatible signature.

base class Vehicle {
  void moveForward(int meters) {
    // ...
  }
}
class MyBaseClass {
    String name;
    int age;

    MyBaseClass(this.name,this.age);

    void introduceYourdelf(){

        print('Hello,my name is $name and I am $age years old.);
    }
}

void main() {

    MyBaseclass person = MyBAseClass('Jeet',18);

    person.introduceYourself();


}
Hello , my name is Jeet and I am 18 years old.



Exited.