当前位置:网站首页>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
边栏推荐
- jmeter性能测试步骤实战教程
- [CF Gym101196-I] Waif Until Dark 网络最大流
- Do you really think binary search is easy
- supervisor 使用文档
- Bit operation XOR
- Yield method of tread
- LeetCode Algorithm 2181. Merge nodes between zero
- 1091: two or three things in childhood (multi instance test)
- Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
- Relevant introduction of clip image
猜你喜欢

Fundamentals of C language 9: Functions
![Jerry's ad series MIDI function description [chapter]](/img/28/e0f9b41db597ff3288af431c677001.png)
Jerry's ad series MIDI function description [chapter]

Set picture annotation in markdown

word中如何删除某符号前面或后面所有的文字

Leetcode 78: subset

C - Inheritance - polymorphism - virtual function member (lower)
![When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]](/img/3e/3d5bff87995b4a9fac093a6d9f9473.png)
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
![Ble of Jerry [chapter]](/img/ce/127b597cdd238bb0c37326f5cf8265.png)
Ble of Jerry [chapter]

Internal and external troubles of "boring ape" bayc

Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
随机推荐
word中把帶有某個符號的行全部選中,更改為標題
Word setting directory
Jerry needs to modify the profile definition of GATT [chapter]
leetcode841. Keys and rooms (medium)
The differences and advantages and disadvantages between cookies, seeion and token
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
CDN acceleration and cracking anti-theft chain function
Internal and external troubles of "boring ape" bayc
navicat如何导入MySQL脚本
剪映的相关介绍
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
可变参数重载时的内存错误
Raspberry pie serial port login and SSH login methods
SEO学习的最好方式:搜索引擎
js對象獲取屬性的方法(.和[]方式)
Idea console color log
Supervisor usage document
Typescript void base type
Méthode d'obtention des propriétés de l'objet JS (.Et [] méthodes)
Typescript variable scope