Dart Flutter中如何实现多继承

发布于 2 个月前 作者 itying888 63 次浏览 最后一次编辑是 2 个月前 来自 分享

在 Dart Flutter 中,使用extends关键字表示继承关系,使用with关键字可以实现多继承

class People {
  String name;
  int age;
  void basicInformation() {
    print('人类信息');
  }
}

// 学生类 使用 extends 关键字表示 Student 类继承自 People 类
class Student extends People {
  String studentId;
  String studentIdentity;
  @override
  void basicInformation() {
    print('学生信息');
  }
}

class Worker {
  String workerId;
  String workerName;
  void workerInfo() {
    print('打工人信息');
  }
}

// myIdentify 类使用 with 继承了 Student 和 Worker 类
class myIdentify extends Student with Worker {
  void infor() {
    print('我的信息');
  }
}

Dart Flutter入门实战基础教程免费学习地址分享:http://bbs.itying.com/topic/620268d1a4bcc00fe8e9d6e1

回到顶部