scala中抽象類_Scala中的抽象類

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中抽象類

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377155.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377155.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377155.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

不能catch Fatal的exception

Clemens Vasters - Are you catching falling knives?里給了一個判斷C#的exception是不是fatal的代碼,可以參考參考。 public static bool IsFatal(this Exception exception) {while (exception ! null){if (exception as OutOfMemoryException ! null &&…

HDU 2824 The Euler function

篩法計算歐拉函數 #include <iostream> #include <cstdio> using namespace std; const int maxn3000005; long long phi[maxn]; int main(){int i,j,a,b;for(i1;i<maxn;i) phi[i]i;for(i2;i<maxn;i2) phi[i]/2;for(i3;i<maxn;i2)if(phi[i]i){for(ji;j<…

LinkChecker 8.1 發布,網頁鏈接檢查

LinkChecker 8.1 可對檢查時間和最大的 URL 數量進行配置&#xff1b;當使用 HTTP 請求時發送 do-not-track 頭&#xff1b;生成 XML 的 sitemap 用于搜索引擎優化&#xff1b;檢測 URL 長度和重復的頁面內容&#xff1b;修復了很多檢查的 bug。 LinkChecker 是一個網頁鏈接檢查…

c語言語言教程0基礎_C語言基礎

c語言語言教程0基礎Hey, Folks here I am back with my second article on C language. Hope you are through with my previous article C language - History, Popularity reasons, Characteristics, Basic structure etc. In this one, I will cover some fundamental conce…

《MySQL——臨時表》

內存表與臨時表區別 臨時表&#xff0c;一般是人手動創建。 內存表&#xff0c;是mysql自動創建和銷毀的。 內存表&#xff0c;指的是使用Memory引擎的表&#xff0c;建表語法&#xff1a;create table ... engine memeory 表的數據存在內存里&#xff0c;系統重啟后會被清…

android中ActionBar的幾個屬性

actionBar.setHomeButtonEnabled //小于4.0版本的默認值為true的。但是在4.0及其以上是false&#xff0c;該方法的作用&#xff1a;決定左上角的圖標是否可以點擊。沒有向左的小圖標。 true 圖標可以點擊 false 不可以點擊。 actionBar.setDisplayHomeAsUpEnabled(true) //…

drei

模擬9 T3 &#xff08;COGS上也有&#xff0c;鏈接http://218.28.19.228/cogs/problem/problem.php?pid1428&#xff09; 題目描述 輸入a&#xff0c;p&#xff0c;求最小正整數x&#xff0c;使得a^x mod p 1。 分析 神奇的歐拉定理&#xff08;對于gcd&#xff08;a&#xf…

《MySQL——group by使用tips》

1、如果對group by語句結果沒有排序要求&#xff0c;在語句后面加order by null 2、盡量讓group by 過程用上索引&#xff0c;確認方法是explain結果里沒有Using temporary 和Using filesort 3、如果group by 需要統計的數據量不大&#xff0c;盡量只使用內存臨時表&#xff…

css中變量_CSS中的變量

css中變量CSS | 變數 (CSS | Variables) CSS variables allow you to create reusable values that can be used throughout a CSS document. CSS變量允許您創建可在CSS文檔中使用的可重用值。 In CSS variable, function var() allows CSS variables to be accessed. 在CSS變…

位圖像素的顏色 攜程編程大賽hdu

位圖像素的顏色 Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 32768/32768 K (Java/Others) Total Submission(s): 0 Accepted Submission(s): 0 Problem Description 有一個在位圖上畫出矩形程序&#xff0c;一開始位圖都被初始化為白色&#xff08;RGB顏色表示…

《MySQL——InnoDB與Memory以及臨時表》

InooDB與Memory 數據組織方式不同&#xff1a; InnoDB引擎把數據放在主鍵索引上&#xff0c;其他索引上保存的是主鍵id。為索引組織表Memory引擎把數據單獨存放&#xff0c;索引上保存數據位置。為堆組織表 典型不同處&#xff1a; 1、InnoDB表的數據總是有序存放的&#x…

Oracle 用戶 profile 屬性 轉

--查看profile 內容 select * from dba_profiles where profilePF_EAGLE; --查看用戶的profiles select username,profile from dba_users; --查看是否啟用動態資源限制參數 SHOW PARAMETER RESOURCE_LIMIT; --啟用限制 ALTER SYSTEM SET RESOURCE_LIMITTRUE SCOPEBOTH; --創建…

CUL8R的完整形式是什么?

CUL8R&#xff1a;稍后再見 (CUL8R: See You Later) CUL8R is an abbreviation of "See You Later". CUL8R是“稍后見”的縮寫 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Yahoo M…

SuperSpider——打造功能強大的爬蟲利器

SuperSpider——打造功能強大的爬蟲利器 博文作者&#xff1a;加菲 發布日期&#xff1a;2013-12-11 閱讀次數&#xff1a;4506 博文內容&#xff1a; 1.爬蟲的介紹 圖1-1 爬蟲&#xff08;spider) 網絡爬蟲(web spider)是一個自動的通過網絡抓取互聯網上的網頁的程序&#xf…

《MySQL——關于grant賦權以及flush privileges》

先上總結圖&#xff1a; 對于賦予權限或者收回權限還是創建用戶&#xff0c;都會涉及兩個操作&#xff1a; 1、磁盤&#xff0c;mysql.user表&#xff0c;用戶行所有表示權限的字段的值的修改 2、內存&#xff0c;acl_users找到用戶對應的對象&#xff0c;將access值修改 g…

對Spring的理解

1、Spring實現了工廠模式的工廠類&#xff0c;這個類名為BeanFactory實際上是一個接口&#xff0c;在程序中通常BeanFactory的子類ApplicationContext。Spring相當于一個大的工廠類&#xff0c;在其配置文件中通過<bean>元素配置用于創建實例對象的類名和實例對象的屬性。…

Java中的null是什么?

As we know null is an important concept in every language not only in Java but here we will study various factors regarding null. 我們知道null在每種語言中都是重要的概念&#xff0c;不僅在Java中&#xff0c;在這里我們還將研究有關null的各種因素。 null is a ver…

《MySQL——分區表小記》

分區表的組織形式 以年份為分割方式&#xff0c;對表進行分割&#xff1a; CREATE TABLE t (ftime datetime NOT NULL,c int(11) DEFAULT NULL,KEY (ftime) ) ENGINEInnoDB DEFAULT CHARSETlatin1 PARTITION BY RANGE (YEAR(ftime)) (PARTITION p_2017 VALUES LESS THAN (201…

實戰Windows下安裝boost

Boost大部分組件無需編譯可直接包含頭文件使用&#xff0c;但還有一些庫需要編譯成靜態庫或動態庫才能使用。可使用下文將提到的bjam工具&#xff1a;bjam --show-libraries 查看必須編譯才能使用的庫。 編譯安裝環境&#xff1a;Win7&#xff0c;VS2008(msvc-9.0) 1. 下載boos…

postgresq dur_DUR的完整形式是什么?

postgresq dur杜爾(DUR)&#xff1a;您還記得嗎&#xff1f; (DUR?: Do You Remember?) DUR? is an abbreviation of "Do You Remember?". DUR&#xff1f; 是“您還記得嗎&#xff1f;”的縮寫。 。 It is an expression, which is commonly used in messaging…