当前位置:网站首页>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
边栏推荐
- Summary of Digital IC design written examination questions (I)
- How to configure GUI guide development environment
- [MySQL learning notes 29] trigger
- 树莓派串口登录与SSH登录方法
- TypeScript 可索引类型
- 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
- TypeScript接口与泛型的使用
- Typescript void base type
- [MySQL learning notes 30] lock (non tutorial)
- 杰理之如若需要大包发送,需要手机端修改 MTU【篇】
猜你喜欢

Leetcode59. spiral matrix II (medium)

TypeScript接口与泛型的使用

Leetcode 78: subset

Lesson 12 study notes 2022.02.11

How Navicat imports MySQL scripts

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

Configure raspberry pie access network

The way to learn go (I) the basic introduction of go to the first HelloWorld

杰理之BLE【篇】
![[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code](/img/93/ec9de907cae4714038bb5f95aba52b.png)
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
随机推荐
Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
作者已死?AI正用藝術征服人類
杰理之BLE【篇】
mysql如何合并数据
JDBC学习笔记
杰理之BLE【篇】
First knowledge of OpenGL es learning (1)
Wechat official account infinite callback authorization system source code, launched in the whole network
Go learning --- use reflection to judge whether the value is valid
Chrome view page FPS
TypeScript 变量作用域
Internal and external troubles of "boring ape" bayc
The way to learn go (I) the basic introduction of go to the first HelloWorld
Get/post/put/patch/delete meaning
How to configure GUI guide development environment
Path analysis model
TypeScript 接口属性
Ble of Jerry [chapter]
Ble of Jerry [chapter]
Raspberry pie 3B update VIM