当前位置:网站首页>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
边栏推荐
- OpenJudge NOI 2.1 1661:Bomb Game
- Simple and understandable high-precision addition in C language
- TypeScript接口与泛型的使用
- Typescript interface properties
- Typescript function definition
- Set picture annotation in markdown
- C语言 简单易懂的高精度加法
- OpenJudge NOI 2.1 1749:数字方格
- Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
- jmeter性能测试步骤实战教程
猜你喜欢
随机推荐
Idea console color log
Typescript void base type
Jerry's general penetration test - do data transmission with app Communication [article]
杰理之普通透传测试---做数传搭配 APP 通信【篇】
Leetcode59. spiral matrix II (medium)
Chrome view page FPS
How can word delete English only and keep Chinese or delete Chinese and keep English
[MySQL learning notes 29] trigger
js對象獲取屬性的方法(.和[]方式)
Bloom taxonomy
LeetCode Algorithm 2181. Merge nodes between zero
leetcode704. Binary search (find an element, simple, different writing)
Bit operation XOR
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
Typescript variable scope
Memory error during variable parameter overload
word删除括号里内容
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
CDN acceleration and cracking anti-theft chain function
Twelve rules for naming variables