当前位置:网站首页>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
边栏推荐
- #systemverilog# 可綜合模型的結構總結
- How Navicat imports MySQL scripts
- 杰理之如若需要大包发送,需要手机端修改 MTU【篇】
- 升级版手机检测微信工具小程序源码-支持多种流量主模式
- Word delete the contents in brackets
- [MySQL learning notes 29] trigger
- Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
- 杰理之AD 系列 MIDI 功能说明【篇】
- MVVM of WPF
- SEO学习的最好方式:搜索引擎
猜你喜欢
杰理之BLE【篇】
Redis builds clusters
Leetcode 78: subset
杰理之AD 系列 MIDI 功能说明【篇】
JDBC learning notes
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
First knowledge of OpenGL es learning (1)
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
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
随机推荐
【mysql学习笔记30】锁(非教程)
OpenJudge NOI 2.1 1661:Bomb Game
可变参数重载时的内存错误
C - Inheritance - polymorphism - virtual function member (lower)
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
Openjudge noi 2.1 1749: Digital Square
Go learning --- use reflection to judge whether the value is valid
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
学go之路(二)基本类型及变量、常量
SEO学习的最好方式:搜索引擎
word设置目录
多线程和并发编程(二)
Chrome view page FPS
Méthode d'obtention des propriétés de l'objet JS (.Et [] méthodes)
[MySQL learning notes 30] lock (non tutorial)
TypeScript 函数定义
Ble of Jerry [chapter]
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
Is software testing outsourcing going or not? Three years' real outsourcing experience tells you