当前位置:网站首页>7. Scala class
7. Scala class
2022-07-05 17:12:00 【Don import someone】
One . class
1. Class definition
Calse Class name ( constructors parameters ) {
Parameter declarations + function +Scala Operation statement
}
2. Class uses
Variable / Constant Object name =new Class name
Two . Class inheritance
1. characteristic
- Same as java The same can only be , Father -> Single line inheritance of children
- Subclasses use the methods of the parent class with keywords override
2. Use
Calse Class name ( constructors parameters ) extends Parent class
{
Parameter declarations + function +Scala Operation statement
}
3. Example
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
3、 ... and . Recessive class
'implicit' Calse Class name ...
- Implicit classes allow implicit conversations with the primary constructor of the class
- An implicit class must be in another class / object / Defined in the feature ( Not on the top floor ).
- An implicit class can only use one non default parameter in its constructor .
- Any method in the scope of an implicit class cannot have the same name as the implicit class , Members or objects .
Four .object( Single object )
- Effect =java Static class
1. characteristic
- Definition cannot take parameters
- There can only be one single column object in the whole program
2. effect
- As the entry point of the program
3. Example
object Demo {
def one() {
println(" Look, this is a static class ")
}
}
Demo.one
defined object Demo
边栏推荐
- Deep learning plus
- easyNmon使用汇总
- 麻烦问下,DMS中使用Redis语法是以云数据库Redis社区版的命令为参考的嘛
- 机器学习01:绪论
- [61dctf]fm
- Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
- Combined use of vant popup+ other components and pit avoidance Guide
- Read the basic grammar of C language in one article
- C language to get program running time
- Timestamp strtotime the day before or after the date
猜你喜欢
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
Embedded-c Language-1
激动人心!2022开放原子全球开源峰会报名火热开启!
[729. My schedule I]
【性能测试】jmeter+Grafana+influxdb部署实战
Error in composer installation: no composer lock file present.
Machine learning compilation lesson 2: tensor program abstraction
Deep learning plus
CMake教程Step1(基本起点)
【Web攻防】WAF检测技术图谱
随机推荐
The first lesson of EasyX learning
高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
How to write a full score project document | acquisition technology
Jarvis OJ Flag
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
深耕5G,芯讯通持续推动5G应用百花齐放
[Web attack and Defense] WAF detection technology map
winedt常用快捷键 修改快捷键latex编译按钮
C language to get program running time
[61dctf]fm
Deep learning plus
Wechat official account web page authorization login is so simple
張平安:加快雲上數字創新,共建產業智慧生態
手机开证券账户安全吗?怎么买股票详细步骤
微信公众号网页授权登录实现起来如此简单
张平安:加快云上数字创新,共建产业智慧生态
flask解决CORS ERR 问题
EasyX second lesson
中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
【二叉树】根到叶路径上的不足节点