当前位置:网站首页>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
边栏推荐
- C how TCP restricts the access traffic of a single client
- Data verification before and after JSON to map -- custom UDF
- 中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
- Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
- Google Earth engine (GEE) -- a brief introduction to kernel kernel functions and gray level co-occurrence matrix
- File operation --i/o
- 【testlink】TestLink1.9.18常见问题解决方法
- 国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」
- Global Data Center released DC brain system, enabling intelligent operation and management through science and technology
- Jarvis OJ shell traffic analysis
猜你喜欢
![[61dctf]fm](/img/22/3e4e3f1679a27d8b905684bb709905.png)
[61dctf]fm

Get ready for the pre-season card game MotoGP ignition champions!

机器学习编译第2讲:张量程序抽象

Learnopongl notes (I)

PHP talent recruitment system development source code recruitment website source code secondary development

兰空图床苹果快捷指令

How to install MySQL

Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)

How was the middle table destroyed?

How to uninstall MySQL cleanly
随机推荐
[Jianzhi offer] 62 The last remaining number in the circle
Jarvis OJ Telnet Protocol
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
微信公众号网页授权登录实现起来如此简单
Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
如何将mysql卸载干净
PHP 严格模式
[echart] resize lodash to realize chart adaptation when window is zoomed
How can C TCP set heartbeat packets to be elegant?
Learnopongl notes (I)
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
Games101 notes (III)
【剑指 Offer】63. 股票的最大利润
JSON转MAP前后数据校验 -- 自定义UDF
Jarvis OJ Webshell分析
Deep dive kotlin synergy (XXI): flow life cycle function
How was the middle table destroyed?
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
[js] skill simplification if empty judgment
tf. sequence_ Mask function explanation case