当前位置:网站首页>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
边栏推荐
- Facing new challenges and becoming a better self -- attacking technology er
- 精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
- [61dctf]fm
- Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
- Global Data Center released DC brain system, enabling intelligent operation and management through science and technology
- Excuse me, is the redis syntax used in DMS based on the commands of the redis community version of the cloud database
- C# TCP如何限制单个客户端的访问流量
- 启牛商学院股票开户安全吗?靠谱吗?
- It is forbidden to copy content JS code on the website page
- Browser rendering principle and rearrangement and redrawing
猜你喜欢

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

Copy mode DMA

Jarvis OJ Webshell分析

Application of threshold homomorphic encryption in privacy Computing: Interpretation

Practical example of propeller easydl: automatic scratch recognition of industrial parts
![[729. My Schedule i]](/img/e3/32914227d00cf7595ee850e60f2b72.png)
[729. My Schedule i]

Cs231n notes (bottom) - applicable to 0 Foundation

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

PHP人才招聘系统开发 源代码 招聘网站源码二次开发

China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
随机推荐
Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
【729. 我的日程安排表 I】
【刷題篇】鹅廠文化衫問題
Summary of methods for finding intersection of ordered linked list sets
SQL injection of cisp-pte (Application of secondary injection)
npm安装
數據訪問 - EntityFramework集成
Jarvis OJ Flag
启牛商学院股票开户安全吗?靠谱吗?
Learnopongl notes (I)
tf. sequence_ Mask function explanation case
【 brosser le titre 】 chemise culturelle de l'usine d'oies
[Jianzhi offer] 61 Shunzi in playing cards
[echart] resize lodash to realize chart adaptation when window is zoomed
【剑指 Offer】61. 扑克牌中的顺子
Wsl2.0 installation
手机开证券账户安全吗?怎么买股票详细步骤
C# TCP如何设置心跳数据包,才显得优雅呢?
[Jianzhi offer] 66 Build product array
Bs-xx-042 implementation of personnel management system based on SSM