当前位置:网站首页>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
边栏推荐
- [Jianzhi offer] 63 Maximum profit of stock
- 中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
- High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
- Deep learning plus
- Judge whether a number is a prime number (prime number)
- stirring! 2022 open atom global open source summit registration is hot!
- 兰空图床苹果快捷指令
- Timestamp strtotime the day before or after the date
- 叩富网开期货账户安全可靠吗?怎么分辨平台是否安全?
- Wechat official account web page authorization login is so simple
猜你喜欢
Embedded-c Language-2
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
[729. My Schedule i]
Wsl2.0 installation
WSL2.0安装
Machine learning compilation lesson 2: tensor program abstraction
中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
[Web attack and Defense] WAF detection technology map
一文了解MySQL事务隔离级别
Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
随机推荐
Embedded UC (UNIX System Advanced Programming) -2
Deep learning plus
Jarvis OJ Telnet Protocol
Is it safe for qiniu business school to open a stock account? Is it reliable?
【机器人坐标系第一讲】
Games101 notes (I)
Etcd 构建高可用Etcd集群
基于51单片机的电子时钟设计
【beanshell】数据写入本地多种方法
CMake教程Step4(安装和测试)
Embedded-c Language-4
Rider 设置选中单词侧边高亮,去除警告建议高亮
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
Games101 notes (II)
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
【剑指 Offer】66. 构建乘积数组
CMake教程Step5(添加系统自检)