Dart 10-Day

静态成员

  • 使用static 关键字来实现类级别的变量和函数
  • 静态方法不能访问非静态成员,非静态方法可以访问静态成员
class Person {
  static String name = '张三';
  static void show() {
    print(name);
  }
}

main() {
  print(Person.name); // 张三
  Person.show(); // 张三
}

class Person {
  static String name = '张三’; // 静态属性
  int age = 20;
  // 静态方法
  static void show() {
    print(name);
  }
  // 静态方法
  static void printUserInfo() {
    print(name); // 静态属性
    show(); // 静态方法
    // print(this.age);     //静态方法没法访问非静态的属性
    // this.printInfo();   //静态方法没法访问非静态的方法
    // printInfo();
  }

  void printInfo() {
    /*非静态方法可以访问静态成员以及非静态成员*/
    print(name);  // 访问静态属性
    print(this.age);  // 访问非静态属性
    show(); //调用静态方法
  }
}

main() {
  print(Person.name);
  Person.show();
  Person p = new Person();
  p.printInfo();
  Person.printUserInfo();
}

Dart中的对象操作符

  • ? 条件运算符
  • as 类型转换
  • is 类型判断
  • .. 级联操作 (连缀)
class Person {
  String name;
  num age;
  Person(this.name, this.age);
  void printInfo() {
    print("${this.name}---${this.age}");
  }
}

main() {
  // Person p;
  // p?.printInfo(); // person未实例化,不存在printInfo()方法,所以未打印

  Person p = new Person('张三', 20);
  p?.printInfo();

  // is的用法
  Person p = new Person('张三', 20);
  if (p is Person) {
    p.name = "李四";
  }
  p.printInfo();
  print(p is Object);

  // as的用法
  var p1;
  p1 = '';
  p1 = new Person('张三1', 20);
  // p1.printInfo(); // 老版本会有问题
  (p1 as Person).printInfo();

  // 重新赋值
  Person p1 = new Person('张三1', 20);
  p1.printInfo();
  p1.name = '张三222';
  p1.age = 40;
  p1.printInfo();

  // 级联操作
  Person p1 = new Person('张三1', 20);
  p1.printInfo();
  p1..name = "李四"
    ..age = 30
    ..printInfo();
}

面向对象的三大特性:封装 、继承、多态

Dart中的类的继承

  • 子类使用extends关键词来继承父类
  • 子类会继承父类里面可见的属性和方法 但是不会继承构造函数
  • 子类能复写父类的方法 getter和setter
class Person {
  String name = '张三';
  num age = 20;
  void printInfo() {
    print("${this.name}---${this.age}");
  }
}

class Web extends Person {}

main() {
  Web w = new Web();
  print(w.name); // 张三
  w.printInfo(); // 张三---20
}

Dart 类的继承 super关键词

  • Dart 类的继承 super关键词的使用 实例化自类给父类构造函数传参
class Person {
  String name;
  num age;
  Person(this.name, this.age);
  void printInfo() {
    print("${this.name}---${this.age}");
  }
}

class Web extends Person {
  Web(String name, num age) : super(name, age) {}
}

main() {
  Person p = new Person('李四', 20);
  p.printInfo(); // 李四---20
  Web w = new Web('张三', 12);
  w.printInfo(); // 张三---12
}

继承后,实现自己的方法

class Person {
  String name;
  num age;
  Person(this.name, this.age);
  void printInfo() {
    print("${this.name}---${this.age}");
  }
}

class Web extends Person {
  String sex;
  Web(String name, num age, String sex) : super(name, age) {
    this.sex = sex;
  }
  run() {
    print("${this.name}---${this.age}--${this.sex}");
  }
}

main() {
  Web w = new Web('张三', 12, "男");
  w.printInfo();
  w.run();
}

实例化自定义构造函数

class Person {
  String name;
  num age;
  Person(this.name, this.age);
  Person.xxx(this.name, this.age);
  void printInfo() {
    print("${this.name}---${this.age}");
  }
}

class Web extends Person {
  String sex;
  Web(String name, num age, String sex) : super.xxx(name, age) {
    this.sex = sex;
  }
  run() {
    print("${this.name}---${this.age}--${this.sex}");
  }
}

main() {
  Web w = new Web('张三', 12, "男");
  w.printInfo();
  w.run();
}

覆写父类的方法,一般要加 @override 标识覆写方法

class Person {
  String name;
  num age;
  Person(this.name, this.age);
  void printInfo() {
    print("${this.name}---${this.age}");
  }

  work() {
    print("${this.name}在工作...");
  }
}

class Web extends Person {
  Web(String name, num age) : super(name, age);

  run() {
    print('run');
  }

  // 覆写父类的方法
  @override // 可以写也可以不写  建议在覆写父类方法的时候加上 @override
  void printInfo() {
    print("姓名:${this.name}---年龄:${this.age}");
  }

  @override
  work() {
    print("${this.name}的工作是写代码");
  }
}

main() {
  Web w = new Web('李四', 20);
  w.printInfo();
  w.work();
}

子类中调用父类方法;

class Person {
  String name;
  num age;
  Person(this.name, this.age);
  void printInfo() {
    print("${this.name}---${this.age}");
  }

  work() {
    print("${this.name}在工作...");
  }
}

class Web extends Person {
  Web(String name, num age) : super(name, age);

  run() {
    print('run');
    super.work(); // 自类调用父类的方法
  }

  @override  // 覆写父类的方法
  void printInfo() {
    print("姓名:${this.name}---年龄:${this.age}");
  }
}

main() {
  Web w = new Web('李四', 20);
  w.printInfo();
  w.run();
}

 Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.https://serious-lose.notion.site/Dart-10-Day-2c7e2133210b47749e29e85d1fea35e2

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DaRT 版本信息 DaRT 10 - Windows 10 DaRT 8.1 - Windows 8.1, Windows Server 2012 R2 DaRT 8.0 - Windows 8, Windows Server 2012 DaRT 7.0 - Windows 7, Windows Server 2008 R2 DaRT 6.5 - Windows 7, Windows Server 2008 R2 DaRT 6.0 - Windows Vista, Windows Server 2008 DaRT 5.0 - Windows 2000, Windows XP, Windows Server 2003 Microsoft Diagnostics and Recovery Toolset (DaRT) 8.1 provides the following enhancements, which are described in this topic. What’s new Support for WIMBoot Diagnostics and Recovery Toolset 8.1 supports the Windows image file boot (WIMBoot) environment if these conditions are met: WIMBoot is based on Windows 8.1 Update 1 or later. The DaRT 8.1 image is built on Windows 8.1 Update 1 or later. For more information about WIMBoot, see Windows Image File Boot (WIMBoot) Overview. Support for Windows Server 2012 R2 and Windows 8.1 You can create DaRT images by using Windows Server 2012 R2 or Windows 8.1. Note For earlier versions of the Windows Server and Windows operating systems, continue to use the earlier versions of DaRT. Customer feedback DaRT 8.1 includes updates that address issues found since the DaRT 8.0 SP1 release. Windows Defender Windows Defender in Windows 8.1 includes improved protection. The changes do not impact how you use DaRT with Windows Defender. Requirements Windows Assessment and Development Kit 8.1 Windows Assessment and Development Kit (ADK) 8.1 is a required prerequisite for the DaRT Recovery Image Wizard. Windows ADK 8.1 contains deployment tools that are used to customize, deploy, and service Windows images. It also contains the Windows Preinstallation Environment (Windows PE). Note Windows ADK 8.1 is not required if you are installing only Remote Connection Viewer or Crash Analyzer.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值