当前位置:网站首页>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
边栏推荐
猜你喜欢

干货!半监督预训练对话模型 SPACE

How to uninstall MySQL cleanly

Accès aux données - intégration du cadre d'entité

Jarvis OJ 远程登录协议

中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户

国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」

Benji Bananas 会员通行证持有人第二季奖励活动更新一览
![[brush title] goose factory shirt problem](/img/c8/44496c767a778101cf3982bd911933.png)
[brush title] goose factory shirt problem

Learnopongl notes (I)

Clear restore the scene 31 years ago, volcanic engine ultra clear repair beyond classic concert
随机推荐
How does the outer disk futures platform distinguish formal security?
How can C TCP set heartbeat packets to be elegant?
npm安装
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
C how TCP restricts the access traffic of a single client
數據訪問 - EntityFramework集成
Summary of PHP pseudo protocol of cisp-pte
如何安装mysql
Jarvis OJ Telnet Protocol
Allusions of King Xuan of Qi Dynasty
兰空图床苹果快捷指令
Twig数组合并的写法
麻烦问下,DMS中使用Redis语法是以云数据库Redis社区版的命令为参考的嘛
If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
Do sqlserver have any requirements for database performance when doing CDC
Solution of vant tabbar blocking content
composer安装报错:No composer.lock file present.
Application of threshold homomorphic encryption in privacy Computing: Interpretation
外盘期货平台如何辨别正规安全?
[729. My Schedule i]