当前位置:网站首页>7.Scala类
7.Scala类
2022-07-05 16:28:00 【唐-import-某人】
一.类
1.类定义
Calse 类名(构造函数参数) {
参数声明+函数+Scala运算语句
}

2.类使用
变量/常量 对象名=new 类名

二.类继承
1.特点
- 同java一样只能是,父->子的单线继承
- 子类使用父类的方法用关键词override
2.使用
Calse 类名(构造函数参数) extends 父类
{
参数声明+函数+Scala运算语句
}
3.示例
abstract class Father{
def fun1=1
def fun2:Int
println("Father_fun1:"+fun1)
println("Father_fun2:"+fun2)
}
class Child extends Father{
override def fun1=3
def fun2=1
println("Child_fun1:"+fun1)
println("Child_fun2:"+fun2)
}
new Child
Father_fun1:3
Father_fun2:1
Child_fun1:3
Child_fun2:1
三.隐性类
'implicit' Calse 类名...
- 隐式类允许与类的主构造函数进行隐式对话
- 隐式类必须在另一个类/对象/特征中定义(不在顶层)。
- 隐式类在其构造函数中只能使用一个非默认参数。
- 隐式类作用域中不可以具有与隐式类相同名称的的任何方法,成员或对象。
四.object(单列对象)
- 作用效果=java的静态类
1.特点
- 定义不能带参数
- 整个程序中只能有一个单列对象
2.作用
- 作为程序的入口点
3.示例
object Demo {
def one() {
println("看这是静态类")
}
}
Demo.one
defined object Demo
边栏推荐
- easyNmon使用汇总
- 精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
- [js] skill simplification if empty judgment
- 【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
- [brush questions] effective Sudoku
- 国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」
- [deep learning] [original] let yolov6-0.1.0 support the txt reading dataset mode of yolov5
- Jarvis OJ Telnet Protocol
- 时间戳strtotime前一天或后一天的日期
- Data access - entityframework integration
猜你喜欢

Detailed explanation of use scenarios and functions of polar coordinate sector diagram

npm安装

Deep dive kotlin synergy (XXI): flow life cycle function
![[61dctf]fm](/img/22/3e4e3f1679a27d8b905684bb709905.png)
[61dctf]fm

How was the middle table destroyed?

The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale

BS-XX-042 基于SSM实现人事管理系统

Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022

Global Data Center released DC brain system, enabling intelligent operation and management through science and technology

阈值同态加密在隐私计算中的应用:解读
随机推荐
[729. My schedule I]
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
[wechat applet] read the life cycle and route jump of the applet
NPM installation
[729. My Schedule i]
为季前卡牌游戏 MotoGP Ignition Champions 做好准备!
File operation --i/o
How to install MySQL
tf. sequence_ Mask function explanation case
dried food! Semi supervised pre training dialogue model space
Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
如何安装mysql
【 brosser le titre 】 chemise culturelle de l'usine d'oies
[js] skill simplification if empty judgment
解决CMakeList find_package找不到Qt5,找不到ECM
數據訪問 - EntityFramework集成
【剑指 Offer】61. 扑克牌中的顺子
Jarvis OJ 远程登录协议
Jarvis OJ webshell analysis