当前位置:网站首页>Scala语言学习-08-抽象类
Scala语言学习-08-抽象类
2022-07-06 07:22:00 【阳光九叶草LXGZXJ】
一、个人理解
(1)抽象类中的常量和变量允许不初始化,定义的方法可以不写方法体。
(2)不允许创建抽象类的实例,不然会提示报错。
(3)抽象类不允许多重继承,即一个类只能继承一个抽象类。
二、测试代码
object TestAbstractClass {
def main(args: Array[String]): Unit = {
val ClassStudent: Student = new Student
ClassStudent.Eat()
println(ClassStudent.age)
println(ClassStudent.name)
}
}
abstract class Person{
//抽象属性可以不初始化值
val name: String
var age: Int
//抽象方法可以不定义方法体
def Eat(): Unit
}
//抽象类继承
class Student extends Person{
override val name: String = "Czg"
override var age = 12
override def Eat(): Unit = {
println("Student Eat !!!")
}
}
三、测试结果
Student Eat !!!
12
Czg
边栏推荐
- Bloom taxonomy
- After the hot update of uniapp, "mismatched versions may cause application exceptions" causes and Solutions
- The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
- C - Inheritance - polymorphism - virtual function member (lower)
- 微信公众号无限回调授权系统源码 全网首发
- MVVM of WPF
- TypeScript 接口属性
- How Navicat imports MySQL scripts
- 学go之路(二)基本类型及变量、常量
- Idea console color log
猜你喜欢

Go learning -- implementing generics based on reflection and empty interfaces

SSM learning

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

leetcode1020. Number of enclaves (medium)

JDBC learning notes

Establishment and operation of cloud platform open source project environment
![[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code](/img/93/ec9de907cae4714038bb5f95aba52b.png)
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code

First knowledge of OpenGL es learning (1)

Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
随机推荐
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
[JDBC] quick start tutorial
JDBC学习笔记
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
Sélectionnez toutes les lignes avec un symbole dans Word et changez - les en titre
杰理之普通透传测试---做数传搭配 APP 通信【篇】
Word setting directory
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
Get/post/put/patch/delete meaning
Summary of Digital IC design written examination questions (I)
Jerry's general penetration test - do data transmission with app Communication [article]
TS基础篇
word中把帶有某個符號的行全部選中,更改為標題
How to configure GUI guide development environment
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
Typescript void base type
TypeScript接口与泛型的使用
软件测试界的三无简历,企业拿什么来招聘你,石沉大海的简历
杰理之AD 系列 MIDI 功能说明【篇】