当前位置:网站首页>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
边栏推荐
猜你喜欢
Bugku CTF daily question: do you want seeds? Blackmailed
[MySQL learning notes 32] mvcc
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
Leetcode59. spiral matrix II (medium)
杰理之AD 系列 MIDI 功能说明【篇】
智能终端设备加密防护的意义和措施
烧录场景下的源代码防泄密方案分享
[MySQL learning notes 30] lock (non tutorial)
Do you really think binary search is easy
Go learning -- implementing generics based on reflection and empty interfaces
随机推荐
Structure summary of SystemVerilog integrable model
Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
【JDBC】快速入门教程
The differences and advantages and disadvantages between cookies, seeion and token
C - Inheritance - polymorphism - virtual function member (lower)
杰理之BLE【篇】
Multithreading and concurrent programming (2)
[CF Gym101196-I] Waif Until Dark 网络最大流
Méthode d'obtention des propriétés de l'objet JS (.Et [] méthodes)
树莓派串口登录与SSH登录方法
Set picture annotation in markdown
Typescript void base type
Simple and understandable high-precision addition in C language
杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】
Bloom taxonomy
TypeScript void 基础类型
Jerry's general penetration test - do data transmission with app Communication [article]
【MySQL学习笔记32】mvcc
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution