当前位置:网站首页>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
边栏推荐
- Project GFS data download
- The way to learn go (I) the basic introduction of go to the first HelloWorld
- OpenGL ES 学习初识(1)
- How MySQL merges data
- Go learning --- use reflection to judge whether the value is valid
- On the world of NDK (2)
- The best way to learn SEO: search engine
- Seriously recommend several machine learning official account
- Typescript void base type
- How can word delete English only and keep Chinese or delete Chinese and keep English
猜你喜欢
The best way to learn SEO: search engine
剪映的相关介绍
Cookie Technology & session Technology & ServletContext object
树莓派3B更新vim
NiO programming introduction
Establishment and operation of cloud platform open source project environment
Redis builds clusters
烧录场景下的源代码防泄密方案分享
The way to learn go (I) the basic introduction of go to the first HelloWorld
idea控制台彩色日志
随机推荐
Word delete the contents in brackets
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
Path analysis model
Yield method of tread
Jerry needs to modify the profile definition of GATT [chapter]
升级版手机检测微信工具小程序源码-支持多种流量主模式
Typescript void base type
呆错图床系统源码图片CDN加速与破解防盗链功能
TypeScript 可索引类型
烧录场景下的源代码防泄密方案分享
CDN acceleration and cracking anti-theft chain function
How to configure GUI guide development environment
You deserve this high-value open-source third-party Netease cloud music player
【MySQL学习笔记32】mvcc
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
SEO学习的最好方式:搜索引擎
MVVM of WPF
Multithreading and concurrent programming (2)
Oracle column to row -- a field is converted to multiple rows according to the specified separator
Set picture annotation in markdown