当前位置:网站首页>Scala language learning-08-abstract classes
Scala language learning-08-abstract classes
2022-07-06 07:25:00 【Sunshine clover lxgzxj】
One 、 Personal understanding
(1) Constants and variables in abstract classes are allowed to be uninitialized , A defined method may not write a method body .
(2) It is not allowed to create instances of abstract classes , Otherwise, it will prompt you to report an error .
(3) Abstract classes do not allow multiple inheritance , That is, a class can only inherit one abstract class .
Two 、 Test code
object TestAbstractClass {
def main(args: Array[String]): Unit = {
val ClassStudent: Student = new Student
ClassStudent.Eat()
println(ClassStudent.age)
println(ClassStudent.name)
}
}
abstract class Person{
// Abstract properties can be uninitialized
val name: String
var age: Int
// Abstract methods may not define method bodies
def Eat(): Unit
}
// Abstract class inheritance
class Student extends Person{
override val name: String = "Czg"
override var age = 12
override def Eat(): Unit = {
println("Student Eat !!!")
}
}
3、 ... and 、 test result
Student Eat !!!
12
Czg
边栏推荐
- The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
- Week6 weekly report
- Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
- 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
- #systemverilog# 可综合模型的结构总结
- Fundamentals of C language 9: Functions
- After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions
- Idea console color log
- leecode-C语言实现-15. 三数之和------思路待改进版
- Wechat official account infinite callback authorization system source code, launched in the whole network
猜你喜欢
SSM学习
C - Inheritance - polymorphism - virtual function member (lower)
Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
First knowledge of OpenGL es learning (1)
leecode-C语言实现-15. 三数之和------思路待改进版
Redis builds clusters
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
Excel的相关操作
How are the open source Netease cloud music API projects implemented?
Solution to the problem of breakthrough in OWASP juice shop shooting range
随机推荐
Leetcode59. spiral matrix II (medium)
Get/post/put/patch/delete meaning
How can word delete English only and keep Chinese or delete Chinese and keep English
Typescript function definition
First knowledge of OpenGL es learning (1)
【mysql学习笔记30】锁(非教程)
SSM学习
Memory error during variable parameter overload
word中把带有某个符号的行全部选中,更改为标题
mysql如何合并数据
The author is dead? AI is conquering mankind with art
[MySQL learning notes 30] lock (non tutorial)
ORACLE列转行--某字段按指定分隔符转多行
QT color is converted to string and uint
js對象獲取屬性的方法(.和[]方式)
Configure raspberry pie access network
超级浏览器是指纹浏览器吗?怎样选择一款好的超级浏览器?
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
杰理之BLE【篇】
Set picture annotation in markdown