当前位置:网站首页>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
边栏推荐
- Jerry needs to modify the profile definition of GATT [chapter]
- Related operations of Excel
- Thought map of data warehouse construction
- js对象获取属性的方法(.和[]方式)
- Methods for JS object to obtain attributes (. And [] methods)
- 杰理之如若需要大包发送,需要手机端修改 MTU【篇】
- Do you really think binary search is easy
- How Navicat imports MySQL scripts
- 杰理之BLE【篇】
- OpenGL ES 学习初识(1)
猜你喜欢
How are the open source Netease cloud music API projects implemented?
学go之路(一)go的基本介绍到第一个helloworld
C - Inheritance - polymorphism - virtual function member (lower)
[MySQL learning notes 32] mvcc
Related operations of Excel
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
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
【MySQL学习笔记32】mvcc
Redis builds clusters
Leetcode 78: subset
随机推荐
Ble of Jerry [chapter]
Résumé de la structure du modèle synthétisable
How MySQL merges data
Jerry's ad series MIDI function description [chapter]
Typescript indexable type
#systemverilog# 可综合模型的结构总结
Typescript void base type
leetcode704. Binary search (find an element, simple, different writing)
(4) Web security | penetration testing | network security web site source code and related analysis
word删除括号里内容
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
The best way to learn SEO: search engine
数字IC设计笔试题汇总(一)
[MySQL learning notes 30] lock (non tutorial)
[CF Gym101196-I] Waif Until Dark 网络最大流
How to delete all the words before or after a symbol in word
Redis builds clusters
Word setting directory
Go learning --- use reflection to judge whether the value is valid