当前位置:网站首页>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
边栏推荐
- 基于51单片机的电子时钟设计
- Embedded -arm (bare board development) -2
- Function sub file writing
- Little knowledge about C language (array and string)
- 【性能测试】jmeter+Grafana+influxdb部署实战
- 高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
- Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
- 网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
- Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
- What else do you not know about new map()
猜你喜欢
Browser rendering principle and rearrangement and redrawing
[729. My Schedule i]
深耕5G,芯讯通持续推动5G应用百花齐放
[first lecture on robot coordinate system]
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
CMake教程Step2(添加库)
Deep dive kotlin synergy (XXI): flow life cycle function
Jarvis OJ Telnet Protocol
Embedded UC (UNIX System Advanced Programming) -1
随机推荐
thinkphp3.2.3
叩富网开期货账户安全可靠吗?怎么分辨平台是否安全?
Three traversal methods of binary tree
thinkphp模板的使用
EasyX second lesson
Application of threshold homomorphic encryption in privacy Computing: Interpretation
CMake教程Step4(安装和测试)
编译libssh2报错找不到openssl
网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
The third lesson of EasyX learning
一文了解MySQL事务隔离级别
Games101 notes (I)
【性能测试】全链路压测
麻烦问下,DMS中使用Redis语法是以云数据库Redis社区版的命令为参考的嘛
激动人心!2022开放原子全球开源峰会报名火热开启!
【剑指 Offer】63. 股票的最大利润
Is it safe to open futures accounts online? Will there be more liars online? Doesn't feel very reliable?
Learnopongl notes (I)
NPM installation
Allusions of King Xuan of Qi Dynasty