当前位置:网站首页>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
边栏推荐
- [first lecture on robot coordinate system]
- 挖财股票开户安全吗?怎么开股票账户是安全?
- Jarvis OJ Telnet Protocol
- Jarvis OJ shell traffic analysis
- Wechat official account web page authorization login is so simple
- Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
- 【刷题篇】有效的数独
- Google Earth Engine(GEE)——Kernel核函数简单介绍以及灰度共生矩阵
- How does the outer disk futures platform distinguish formal security?
- Wsl2.0 installation
猜你喜欢
Jarvis OJ 远程登录协议
[Jianzhi offer] 63 Maximum profit of stock
Get ready for the pre-season card game MotoGP ignition champions!
How does win11 change icons for applications? Win11 method of changing icons for applications
Jarvis OJ Webshell分析
Browser rendering principle and rearrangement and redrawing
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
數據訪問 - EntityFramework集成
American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
【性能测试】jmeter+Grafana+influxdb部署实战
随机推荐
[729. My Schedule i]
ECU introduction
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
C# TCP如何限制单个客户端的访问流量
Deep learning plus
[Jianzhi offer] 66 Build product array
【刷题篇】有效的数独
[echart] resize lodash to realize chart adaptation when window is zoomed
How to install MySQL
File operation --i/o
手机开证券账户安全吗?怎么买股票详细步骤
Data access - entityframework integration
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
WSL2.0安装
Combined use of vant popup+ other components and pit avoidance Guide
The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
Games101 notes (I)
The difference between searching forward index and inverted index
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale