当前位置:网站首页>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
边栏推荐
- Etcd 构建高可用Etcd集群
- Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
- Iphone14 with pill screen may trigger a rush for Chinese consumers
- mysql如何使用JSON_EXTRACT()取json值
- Deep learning plus
- Embedded UC (UNIX System Advanced Programming) -3
- easyNmon使用汇总
- C how TCP restricts the access traffic of a single client
- Judge whether a number is a prime number (prime number)
- 【机器人坐标系第一讲】
猜你喜欢

CMake教程Step2(添加库)

阈值同态加密在隐私计算中的应用:解读

Games101 notes (I)

Deeply cultivate 5g, and smart core continues to promote 5g applications
基于Redis实现延时队列的优化方案小结

【729. 我的日程安排表 I】

High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body

采用药丸屏的iPhone14或引发中国消费者的热烈抢购

Jarvis OJ webshell analysis

ECU简介
随机推荐
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
【机器人坐标系第一讲】
Embedded-c Language-2
【性能测试】jmeter+Grafana+influxdb部署实战
Learnopongl notes (I)
Embedded UC (UNIX System Advanced Programming) -1
Is it safe for qiniu business school to open a stock account? Is it reliable?
The third lesson of EasyX learning
CMake教程Step3(添加库的使用要求)
What else do you not know about new map()
网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
Embedded -arm (bare board development) -2
高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
Detailed explanation of printf() and scanf() functions of C language
C language to get program running time
Little knowledge about C language (array and string)
thinkphp3.2.3
Timestamp strtotime the day before or after the date
Embedded-c Language-5