当前位置: 首页 > java >正文

Flutter Dart中的类 对象

Dart 基本特征

私有属性/私有方法

import 'test88.dart';main() {var home = new MainHome();home.execRun(); //间接的调用私有方法
}class MainHome {String _name = "张三";//私有属性int age = 10;main() {_run();print(_name);}void _run() {print("私有方法");}execRun() {this._run();}
}

get用法

  var rect = Rect(10, 2);var rect1 = Rect1(10, 2);print( "面积是= ${rect.area()}");print( "面积是= ${rect1.area}");//注意调用直接通过访问属性的方式访问arearect1.areaHeight=6;print( "面积是= ${rect1.area}");class Rect {num height;num width;Rect(this.height, this.width);//方法area() {return this.height * this.width;}
}class Rect1 {num height;num width;Rect1(this.height, this.width);//get用法get area {return this.height * this.width;}//方法set areaHeight(value) {this.height = value;}
}

构造函数体运行之前初始化实例变量
 

class Rect2 {num height;num width;//可以在构造函数体运行之前初始化实例变量Rect2():height =3,width=2 {print("height =$height ---- width=$width");}//get用法get area {return this.height * this.width;}//方法set areaHeight(value) {this.height = value;}
}

http://www.xdnf.cn/news/1807.html

相关文章:

  • 05-GPIO原理
  • 「零配置陷阱」:现代全栈工具链的复杂度管控实践
  • java多线程(7.0)
  • 发放优惠券
  • Java常用API详解
  • 通过VIN车辆识别代码查询_精准版API,获取车辆精准参数
  • 并发编程【深度解剖】
  • Android学习总结之Glide篇(缓存和生命周期)
  • 数据结构与算法(十二):图的应用-最小生成树-Prim/Kruskal
  • 人工智能---当机器人遇到大模型会产生火花吗?
  • 【C++】STL之deque
  • CPU 虚拟化机制——受限直接执行 (LDE)
  • 悟空统计在SEO优化中的核心作用:外链质量评估
  • SpringBoot入门实战(第八篇:项目接口-订单管理)完结篇
  • 高功率激光输出稳定性不足?OAS 光学软件来攻克
  • ap无法上线问题定位(交换机发包没有剥掉pvid tag)
  • 配置模块开发
  • 删除elementplus的li标签中的一个class属性?
  • Vivado与Modelsim联合仿真卡在Executing analysis and compilation step...
  • 利用 Claw Cloud Run 免费应用部署前端网页
  • 天梯——L1-110 这不是字符串题
  • navicat数据表筛选删除空白行
  • 革新AI生产力,比象AI源码 - 下一代智能创作引擎
  • 【android bluetooth 协议分析 06】【l2cap详解 9】【L2cap通道生命周期】
  • RK3588芯片NPU的使用:官方rknn_yolov5_android_apk_demo运行与解读
  • 智慧景区国标GB28181视频平台EasyGBS视频融合应用全场景解决方案
  • hackmyvm-atom
  • 第17章:MCP框架构建知识工作助手
  • MySQL的下载、安装、配置
  • LeetCode算法题(Go语言实现)_60