scala中抽象类

抽象类 (Abstract Class)

In the Scala programming language, abstraction is achieved using abstract class.

在Scala编程语言, 抽象是使用抽象类来实现的。

Abstraction is the process of showing only functionality and hiding the details from the final user.

抽象是仅显示功能并向最终用户隐藏细节的过程。

Abstract classes are defined using the "abstract" keyword. An abstract class contains both abstract and non-abstract methods. Multiple inheritances are not allowed by abstract class i.e. only one abstract class can be inherited by a class.

抽象类使用“抽象”关键字定义。 抽象类包含抽象方法和非抽象方法。 抽象类不允许多重继承,即一个类只能继承一个抽象类。

Syntax to create Abstract Class in Scala:

在Scala中创建Abstract类的语法:

abstract class class_name {def abstract_method () {}
def method() {//code
}
}

An abstract method is that method which does not have any function body.

抽象方法是没有任何函数体的方法。

Example:

例:

abstract class bikes
{
def displayDetails()
}
class myBike extends bikes
{
def displayDetails()
{
println("My new bike name : Harley Davidson Iron 833 ")
println("Top speed : 192 kmph")
}
}
object MyObject
{
def main(args: Array[String])
{
var newBike = new myBike()
newBike.displayDetails()
}
}

Output

输出量

My new bike name : Harley Davidson Iron 833
Top speed : 192 kmph

Some Points about Abstract Classes in Scala

关于Scala抽象类的几点

  • Instance creation of Abstract class is not allowed. If we try to create objects of abstract class then an error will be thrown.

    不允许创建Abstract类的实例。 如果我们尝试创建抽象类的对象,则将引发错误。

  • Field creation of an abstract class is allowed and can be used by methods of abstract class and classes that inherit it.

    允许抽象类的字段创建,并且抽象类的方法和继承它的类都可以使用该字段。

  • A constructor can also be created in an abstract class which will be invoked by the instance of the inherited class.

    也可以在抽象类中创建构造函数,该抽象类将由继承的类的实例调用。

翻译自: https://www.includehelp.com/scala/abstract-classes.aspx

scala中抽象类

scala中抽象类_Scala中的抽象类相关推荐

  1. scala 方法重载_Scala中的方法重载

    scala 方法重载 Scala方法重载 (Scala method overloading) Method overloading is a method that is redefined in ...

  2. scala元组 数组_Scala中的数组

    scala元组 数组 Scala中的数组 (Arrays in Scala) An array is a linear data structure with a fixed number of el ...

  3. scala 方法调用_Scala中的方法调用

    scala 方法调用 Scala方法调用 (Scala Method Invocation) Method invocation is the legal and correct technique ...

  4. scala 字段覆盖_Scala中的字段覆盖

    scala 字段覆盖 Scala字段覆盖 (Scala field overriding) Overriding is the concept in which the child class is ...

  5. scala 字符串函数_Scala中的字符串chomp(或chop)函数

    scala 字符串函数 剁或剁弦 (Chop or Chomp string) It is used to chop off the end of line characters. For this ...

  6. java中graphics抽象类_Java中的抽象类

    抽象类 抽象是一种概念,而不是如何实现,比如你的老板说,大家加油哈,将来发财了人人有份.又如,好好学,将来必成大牛,这些都可以理解成是一种抽象的,你也可以理解成所谓的抽象就是光说不做. 在Java中通 ...

  7. java 中普通类继承,抽象类继承,接口类继承,子类一定要重写父类中的方法吗

    一.简单总结,需要重写的有 普通类继承抽象类,重写所有抽象类方法:(不包括普通方法) 普通类继承接口,重写所有接口方法.(不包括default关键字修饰的方法) 详解见下: 普通类继承,并非一定要重写 ...

  8. java画板抽象类_java 中的 抽象方法 抽象类 和 接口有啥瓜葛

    文章目录 什么是java中的抽象方法 抽象方法是一种特殊的方法: 它只有声明,而没有具体的实现 例如: abstract void eat(); 上面定义了一个方法 eat() ,有修饰关键词 abs ...

  9. python中的装饰器和抽象类

    装饰器和抽象类 装饰器就是对函数或者方法或者类进行修饰 ''' #第一步:创建一个普通函数 def laxi():print('噗哧噗哧噗哧噗哧---')#调用函数 laxi() laxi() ''' ...

最新文章

  1. XMPP文件传输协议笔记
  2. 算法----两数之和
  3. mysql8.0.12插件_mysql 8.0.12 安装使用教程
  4. 【Java面试题】docker启动失败原因
  5. ASP.NET MVC3中Controller与View之间的数据传递总结
  6. 全球最大sap hana系统建立在以下哪个厂商的服务器产品上,全球最大sap hana系统建立在以下哪个厂商的服务器产品上...
  7. logstash 过虑nginx访问日志
  8. android屏幕亮度权限,安卓支持将屏幕亮度设为0的方法。
  9. !heap 和 _HEAP_ENTRY
  10. C#调用DLL函数方法
  11. 实现应用于AlphaGo得增强式学习算法,代码实现1
  12. dell5580bios恢复出厂_戴尔笔记本如何恢复Bios出厂设置?
  13. python图片内容长度识别_python 图片中的表格识别
  14. python语音合成并播放_用Python写一个语音播放软件
  15. TZT3818Y 静态信号测试分析系统
  16. 鸿蒙系统转正,鸿蒙首发机型确定 “备胎”鸿蒙系统正式转正
  17. android标签云:LabelView
  18. PPT文档播放没声音了怎么办?
  19. Let's Encrypt证书自动更新
  20. bzoj 1737: [Usaco2005 jan]Naptime 午睡时间 (DP)

热门文章

  1. 【APICloud系列|33】通过程序循环数据集合的时候闭包加入imageCache方法
  2. 百度开发平台提交应用后进行官方认证审核失败?
  3. java 获取mysql链接_Java中如何获取mysql连接的3种方法总结
  4. php 正则 回溯,php 正则表达式效率 贪婪、非贪婪与回溯分析
  5. Sass学习之路(3)——Sass编译
  6. 全方位分析web前端如何进行性能优化
  7. Vue2.0 --- vue-cli脚手架中全局引入JQ
  8. CSS 水平垂直居中
  9. 字符数组和字符串的小细节
  10. Gradle Introduction