首页 > 建站教程 > dart >  dart笔记8:dart abstract抽象类和接口实现多继承效果正文

dart笔记8:dart abstract抽象类和接口实现多继承效果

dart笔记8:dart abstract抽象类和接口实现多继承效果
void main() {
  Dog dog = Dog();

  dog.name = '小狗';
  dog.public();
  dog.swim();
  dog.walk();
}

abstract class Animal {
  String name;
  void public();
}

abstract class SwimAbility {
  void swim();
}

abstract class WalkAbility {
  void walk();
}

//implements接口和extends配合实现类似java的多继承
class Dog extends Animal implements SwimAbility, WalkAbility {
  @override
  void public() {
    print('动物的名字是:$name');
  }

  @override
  void swim() {
    print('${name}有游泳的能力');
  }

  @override
  void walk() {
    print('${name}有跑步的能力');
  }
}