当前位置:网站首页>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
边栏推荐
- Select all the lines with a symbol in word and change them to titles
- Jerry's ad series MIDI function description [chapter]
- TypeScript 可索引类型
- [online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
- Multithreading and concurrent programming (2)
- Ble of Jerry [chapter]
- 【MySQL学习笔记32】mvcc
- jmeter性能测试步骤实战教程
- Typescript indexable type
- 多线程和并发编程(二)
猜你喜欢

L'auteur est mort? Ai utilise l'art pour conquérir l'humanité

作者已死?AI正用藝術征服人類

Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

JDBC学习笔记

The best way to learn SEO: search engine

The author is dead? AI is conquering mankind with art

Configure raspberry pie access network

杰理之BLE【篇】

Bugku CTF daily question: do you want seeds? Blackmailed
随机推荐
How Navicat imports MySQL scripts
剪映的相关介绍
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
TS基础篇
OpenJudge NOI 2.1 1749:数字方格
#systemverilog# 可綜合模型的結構總結
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
leetcode1020. Number of enclaves (medium)
Supervisor usage document
Bugku CTF daily question: do you want seeds? Blackmailed
Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
How MySQL merges data
word中把带有某个符号的行全部选中,更改为标题
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
js對象獲取屬性的方法(.和[]方式)
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
MVVM of WPF
Leetcode59. spiral matrix II (medium)
Ble of Jerry [chapter]