当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
树莓派串口登录与SSH登录方法
C - Inheritance - hidden method
Jerry needs to modify the profile definition of GATT [chapter]
LeetCode Algorithm 2181. Merge nodes between zero
OpenJudge NOI 2.1 1661:Bomb Game
Ble of Jerry [chapter]
TypeScript void 基础类型
Uni app third party package configuration network request
Establishment and operation of cloud platform open source project environment
Get/post/put/patch/delete meaning
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
word中把帶有某個符號的行全部選中,更改為標題
变量的命名规则十二条
可变参数重载时的内存错误
js对象获取属性的方法(.和[]方式)
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
[JDBC] quick start tutorial







![When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]](/img/3e/3d5bff87995b4a9fac093a6d9f9473.png)

![Ble of Jerry [chapter]](/img/ce/127b597cdd238bb0c37326f5cf8265.png)