scala 訪問修飾符_Scala中的訪問修飾符

scala 訪問修飾符

Access modifiers are used in order to restrict the usage of a member function to a class or a package. Using access modifiers data hiding takes place which is a very important concept of OOPs.

訪問修飾符用于將成員函數的使用限制為類或包。 使用訪問修飾符進行數據隱藏,這是OOP的非常重要的概念。

The access to a class, object or a package can be restricted by the use of three types of access modifiers that are 1) public (accessible to everyone), 2) private (accessible only in the class), and 3) protected (accessible to class and its subclasses).

可以通過使用三種類型的訪問修飾符來限制對類,對象或包的訪問: 1)公共(所有人都可以訪問)2)私有(僅在類中可以訪問)3)受保護(可以訪問)類及其子類)

1)公共訪問修飾符 (1) Public access modifier )

It is the default type of modifier in Scala. In Scala, if you do not use any access modifier then the member is public. Public members can be accessed from anywhere.

它是Scala中默認的修飾符類型。 在Scala中,如果不使用任何訪問修飾符,則該成員是公共的。 可以從任何地方訪問公共成員。

Syntax:

句法:

    def function_name(){}
or 
public def fuction_name(){}

2)私人訪問修飾符 (2) Private access modifier )

In private access, access to the private member is provided only to other members of the class (block). It any call outside the class is treated as an error.

在私有訪問中,對私有成員的訪問僅提供給該類的其他成員(塊)。 在類之外的任何調用都被視為錯誤。

Syntax:

句法:

    private def function_name(){}

3)受保護的訪問修飾符 (3) Protected access modifier )

In protected access, the availability of the member function is limited to the same class and its subclass. Excess without inheritance is treated as an error.

在受保護的訪問中,成員函數的可用性僅限于同一類及其子類。 沒有繼承的多余部分將被視為錯誤。

Syntax:

句法:

    protected def function_name(){}

Scala示例演示使用公共,私有和受保護的訪問修飾符 (Scala example to demonstrate use of public, private and protected access modifiers)

class school(rlno: Int , sname : String ,sch_no : Int) {
//roll no can only be used by school or its subclasses
protected  var rollno = rlno; 
var name = sname;
// this variable is only for the class
private var scholar=sch_no; 
}
class seventh extends school {
def dispaly(){
// public and private member are used...
print("Roll no of " + name + " is " + rollno) 
}
}

翻譯自: https://www.includehelp.com/scala/access-modifiers-in-scala.aspx

scala 訪問修飾符

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

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

相關文章

小試---EF5.0入門實例1

現在做個小練習吧~~~ 第一步:首先新建一個數據庫名字為Test;數據庫里面只有一個表UserTable 腳本為: USE [master] GO /****** 對象: Database [Test] 腳本日期: 12/15/2013 18:51:54 ******/ CREATE DATABASE [Test] ON PRIMARY ( NAME NTest, F…

iScroll4 禁止select等頁面元素默認事件的解決方法 轉

iScroll4 禁止select等頁面元素默認事件的解決方法起因在于onBeforeScrollStart : function(e){ e.preventDefault(); },這一行,iSroll禁止了事件的默認行為,導致select,option,textarea等元素無法點擊。解決方法也很簡單&#xf…

C++中比較兩個浮點數是否相等

來源&#xff1a; https://stackoverflow.com/a/37686/3242645 代碼&#xff1a; #include <cmath> #include <limits> bool AreSame(double a, double b) {return std::fabs(a - b) < std::numeric_limits<double>::epsilon(); }

MPEG的完整形式是什么?

MPEG&#xff1a;運動圖像專家組 (MPEG: Moving Picture Experts Group) MPEG is an abbreviation of Moving Picture Experts Group. It is a working group of authorities that is founded to establish standards for audio and video compression and transmission. The a…

正則 去除html標記

//string regexstr "<[^>]*>"; //去除所有的標簽 //"<script[^>]*?>.*?</script>" //去除所有腳本&#xff0c;中間部分也刪除 // string regexstr "<img[^>]*>"; //去除圖片的正則 // string regexstr &…

自畫PopMenu彈出

BorderColor:TColor; //邊框顏色FillColor:TColor; //未選中填充顏色TextColor:TColor; //未選中字體顏色SelectTextColor:TColor; //選中字體顏色SelectFillColor:TColor; //選中填充顏色SideBuffer:Integer; //邊框寬度procedure TForm1.FormCreate(Sender: TObject); b…

安利一款倒計時插件---雨滴桌面

內容來自B站(搜索Rainmeter即可)&#xff0c;里面教程很多&#xff0c;因為視頻看的有點麻煩&#xff0c;故進行了整理 一、下載安裝包、解壓、安裝 免費下載連接&#xff0c;不需要積分 skin文件夾存放皮膚的一些配置文件&#xff0c;因為原本皮膚太low了 第二個是可執行文…

【C++基礎】自定義異常類與多重捕獲

目錄自定義異常類構建過程例&#xff1a;Vec3D類的數組下標越界的異常類捕獲多種無關異常不同的異常的捕獲捕獲派生異常異常處理的次序例子&#xff1a;多重捕獲異常類catch塊的參數類型可以不用引用類型嗎?自定義異常類 自定義異常類通常由exception或其后代類派生。這樣我們…

gprs 睡眠模式_GPRS的完整形式是什么?

gprs 睡眠模式GPRS&#xff1a;通用分組無線業務 (GPRS: General Packet Radio Service) GPRS is an abbreviation of General Packet Radio Service. It is a non-voice, high-level speed packet switching technology planned for GSM networks. On 2G and 3G cellular tran…

int main(int argc,char* argv[])講解

分類&#xff1a; 學習筆記2011-11-07 21:502354人閱讀評論(0)收藏舉報dos編譯器pathunixcommandc在最近學習中老是遇到 int main(int argc,char* argv[])&#xff0c;以為就是簡單的參數應用了&#xff0c;但是看代碼是沒能理解參數的具體傳遞過程&#xff0c;上網…

Maven實戰(七)——常用Maven插件介紹(上)

我們都知道Maven本質上是一個插件框架&#xff0c;它的核心并不執行任何具體的構建任務&#xff0c;所有這些任務都交給插件來完成&#xff0c;例如編譯源代碼是由maven-compiler-plugin完成的。進一步說&#xff0c;每個任務對應了一個插件目標&#xff08;goal&#xff09;&a…

【設計模式之美】<Reading Notes>抽象類與接口

抽象類特性 1、抽象類不允許被實例化&#xff0c;只能被繼承。 2、抽象類可以包含屬性和方法。方法既可以包含代碼實現&#xff0c;也可以不包含代碼實現。不包含代碼實現的方法叫做抽象方法。 3、子類繼承抽象類&#xff0c;必須實現抽象類中的所有抽象方法。 接口特性 1、…

多線程之間共享數據的實現

1&#xff1a;如果每個線程執行的代碼相同&#xff0c;可以使用同一個Runnable對象&#xff0c;然后將共享的數據放在Runnable里面&#xff0c;來實現數據的共享。 例如買票系統... package com.cn.gbx;import java.util.Date; import java.util.Random; import java.util.Time…

AIX的完整形式是什么?

AIX&#xff1a;高級交互式主管 (AIX: Advanced Interactive Executive) AIX is an abbreviation of "Advanced Interactive Executive". AIX是“ Advanced Interactive Executive”的縮寫 。 It is a progression sequence of proprietary UNIX operating systems …

c#生成隨機字符串 用做批量申請賬號時的隨機密碼還是相當不錯的

//隨機字符串生成器的主要功能如下&#xff1a; //1、支持自定義字符串長度 //2、支持自定義是否包含數字 //3、支持自定義是否包含小寫字母 //4、支持自定義是否包含大寫字母 //5、支持自定義是否包含特殊符號 //6、支持自定義字符…

【C++基礎】C++11的noexcept聲明符 與 異常傳播

目錄C noexcept&#xff1a;1、用途2、用法1、noexcept聲明符的用法&#xff1a;2、noexcept運算符的用法異常傳播1、異常傳播的定義2、異常傳播中的規則3、異常傳播的代價C noexcept&#xff1a; 1、用途 C11使用noexcept指明函數是否拋出異常&#xff1a; 若函數不拋異常&a…

使用IndexReader.repen提高搜索速度

1,使用indexreader創建indexsearcher. 2,indexsearcher在使用完了以后不要關閉. 3.使用indexreader.isCurrent()判斷索引是否被indexwriter改動. 4,如果索引被改動,indexsearcher.close()先前那個,然后new indexsearcher(indexreader). 傳string給searcher,searcher會維護一個內…

CSS中的文本格式

CSS文字格式 (CSS text formatting) CSS text properties allow you to style your text in various ways very easily. Such as color, alignment, spacing, direction, etc. CSS文本屬性使您可以輕松地以各種方式設置文本樣式。 例如顏色 &#xff0c; 對齊方式 &#xff0c;…

【C++基礎】重拋異常與異常的使用場景

重拋異常 異常處理程序可以重新拋出異常。 當它無法處理該異常&#xff0c;或想通知它的調用者發生了一個異常&#xff0c;此時就需要重拋異常&#xff1a; 1、拋出捕獲的異常 try {// statements; } catch (TheException &ex) {// Do something;throw; }2、重新拋出另一…

vi @-function

vi 的功能 vi 是一個越用越強大的東西 功能&#xff1a; 例&#xff1a; 1 在插入模式 cwgadfly CTL-V ESC 看到的似&#xff1a; cwgadfly^[ 2 保存到g緩沖區 ESC :退出插入模式 "gdd :"g 指緩沖去個 dd刪除一行 這樣g緩沖去的內容是 cwgadflayESC 3 test love u 在…