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.mzph.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 在…