当前位置:网站首页>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
边栏推荐
- Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
- The difference between searching forward index and inverted index
- 时间戳strtotime前一天或后一天的日期
- 面对新的挑战,成为更好的自己--进击的技术er
- Deep learning plus
- Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)
- The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
- 阈值同态加密在隐私计算中的应用:解读
- Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
- Excuse me, is the redis syntax used in DMS based on the commands of the redis community version of the cloud database
猜你喜欢

养不起真猫,就用代码吸猫 -Unity 粒子实现画猫咪
![[brush questions] effective Sudoku](/img/5b/3064170bebd1ccbee68d6a85d23830.png)
[brush questions] effective Sudoku

【729. 我的日程安排錶 I】
![[brush title] goose factory shirt problem](/img/c8/44496c767a778101cf3982bd911933.png)
[brush title] goose factory shirt problem

Games101 notes (II)

文件操作--I/O

【刷题篇】鹅厂文化衫问题

Cs231n notes (bottom) - applicable to 0 Foundation

Clear restore the scene 31 years ago, volcanic engine ultra clear repair beyond classic concert

Benji Bananas 会员通行证持有人第二季奖励活动更新一览
随机推荐
Solution of vant tabbar blocking content
【刷題篇】鹅廠文化衫問題
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
【729. 我的日程安排表 I】
easyNmon使用汇总
Jarvis OJ 简单网管协议
调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
Error in composer installation: no composer lock file present.
手机开证券账户安全吗?怎么买股票详细步骤
[echart] resize lodash to realize chart adaptation when window is zoomed
挖财股票开户安全吗?怎么开股票账户是安全?
Browser rendering principle and rearrangement and redrawing
JSON转MAP前后数据校验 -- 自定义UDF
Data access - entityframework integration
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
【 brosser le titre 】 chemise culturelle de l'usine d'oies
Clear restore the scene 31 years ago, volcanic engine ultra clear repair beyond classic concert
Jarvis OJ Webshell分析
飞桨EasyDL实操范例:工业零件划痕自动识别
【刷题篇】鹅厂文化衫问题