当前位置:网站首页>Scala语言学习-08-抽象类
Scala语言学习-08-抽象类
2022-07-06 07:22:00 【阳光九叶草LXGZXJ】
一、个人理解
(1)抽象类中的常量和变量允许不初始化,定义的方法可以不写方法体。
(2)不允许创建抽象类的实例,不然会提示报错。
(3)抽象类不允许多重继承,即一个类只能继承一个抽象类。
二、测试代码
object TestAbstractClass {
def main(args: Array[String]): Unit = {
val ClassStudent: Student = new Student
ClassStudent.Eat()
println(ClassStudent.age)
println(ClassStudent.name)
}
}
abstract class Person{
//抽象属性可以不初始化值
val name: String
var age: Int
//抽象方法可以不定义方法体
def Eat(): Unit
}
//抽象类继承
class Student extends Person{
override val name: String = "Czg"
override var age = 12
override def Eat(): Unit = {
println("Student Eat !!!")
}
}
三、测试结果
Student Eat !!!
12
Czg
边栏推荐
- Oracle column to row -- a field is converted to multiple rows according to the specified separator
- [online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
- If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
- 杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
- 可变参数重载时的内存错误
- Bloom taxonomy
- JDBC学习笔记
- 1091: two or three things in childhood (multi instance test)
- The author is dead? AI is conquering mankind with art
- 【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
猜你喜欢

ORACLE列转行--某字段按指定分隔符转多行
![Ble of Jerry [chapter]](/img/ce/127b597cdd238bb0c37326f5cf8265.png)
Ble of Jerry [chapter]

杰理之BLE【篇】

Babbitt | metauniverse daily must read: the group image of Chinese Internet enterprises pouring into metauniverse: "there are only various survival desires, and there is no ambition for forward-lookin

Wechat official account infinite callback authorization system source code, launched in the whole network

Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
![If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]](/img/57/12a97ab3d2dabfaf06bbe1788450cf.png)
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
![When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]](/img/3e/3d5bff87995b4a9fac093a6d9f9473.png)
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]

Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied

【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
随机推荐
Chrome view page FPS
Structure summary of SystemVerilog integrable model
SSM learning
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
SEO学习的最好方式:搜索引擎
Markdown 中设置图片图注
微信公众号无限回调授权系统源码 全网首发
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
数字IC设计笔试题汇总(一)
Word setting directory
杰理之BLE【篇】
Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
【mysql学习笔记30】锁(非教程)
Supervisor usage document
MPLS experiment
Redis builds clusters
Raspberry pie serial port login and SSH login methods
C - Inheritance - hidden method
[MySQL learning notes 32] mvcc
C语言 简单易懂的高精度加法