scala 类中的对象是类

Scala中的课程 (Classes in Scala)

A class is a blueprint for objects. It contains the definition of all the members of the class. There are two types of members of the class in Scala,

类是对象的蓝图。 它包含该类的所有成员的定义。 Scala中有两种类型的班级成员,

  1. Fields: the variables in Scala that are used to define data in the class.

    字段: Scala中用于定义类中数据的变量。

  2. Methods: The functions of a class that are used to manipulate the fields of the class and do some stuff related to the functioning of a class.

    方法:类的功能,用于操纵类的字段并做一些与类的功能有关的事情。

Usage of a class member to the outer worlds is limited and can be excessed by only two ways,

类成员对外部世界的使用是有限的,并且只能通过两种方式加以超越:

  1. Inheritance: Property by which members of one class are used by child class which inherits it.

    继承:继承该子类的子类使用一个类的成员的属性。

  2. Objects: It is creating instances of a class to use its members.

    对象:它正在创建类的实例以使用其成员。

类的例子 (Example of a class)

We will use the classical student class for the explanation of class creation in Scala. Here, we have a class student, with fields: roll no, name, and percentage. There are methods to this class: getpercentage(), printresult().

我们将使用经典的学生课堂来解释Scala中课堂创建 。 在这里,我们有一个班级学生 ,具有以下字段: 卷号 , 名称和百分比 。 此类有一些方法: getpercentage() , printresult() 。

The blueprint is shown in the below figure...

蓝图如下图所示。

Syntax of class in Scala:

Scala中类的语法:

Class student{// Class Variables
var rollno;
var name : string;
var percentage;
//Class methods…
def getpercentage(int percent){percentage = percent;
}
def printresult(){print("Roll number : " + rollno);
print("\nName  : "+ name);
print("\nHas scored " + percentage + "% and is ");
if(percentage > 40)
print("passed")
else
print("failed")
}
}

Syntax explanation:

语法说明:

The about is a code snippet to declare a class in Scala,

about是在Scala中声明类的代码段,

First, the class is declared keyword class is used to create a class followed by the name of the class. Next is the definition of the class members, the class contains three members all are public (because of var declaration). It also contains two member functions(methods) that are declared using def keyword (no need of return type), followed by the name of the function and then within the "(" are the arguments that are passed when the function is called.

首先,该类被声明为关键字class ,用于创建一个类,后跟该类的名称。 接下来是类成员的定义,该类包含三个成员,所有成员都是公共的(由于var Declaration )。 它还包含两个成员函数(方法),这些成员函数使用def关键字(不需要返回类型)声明,然后是函数名称,然后在“(”内)是调用函数时传递的参数。

Scala的主要构造函数 (Primary Constructor in Scala )

There is a new declaration of class in Scala, and you will see it very it is more efficient than the classical one.

Scala中有一个新的类声明,您会发现它比经典的声明效率更高。

It is the use of primary constructor definition in Scala.

它在Scala中使用了主要的构造函数定义。

    class student (var rlno , var stname){
var rollno = rlno;
var name = stname;
}

Explanation:

说明:

Here the class body is acting as a constructor and is used to initialize the values of fields.

在这里,类主体充当构造函数,并用于初始化字段的值。

This is all about classes in Scala we will learn about objects, their creation, and usage in the next tutorial.

这一切都与Scala中的类有关,我们将在下一个教程中了解对象,对象的创建和用法。

翻译自: https://www.includehelp.com/scala/classes-and-objects-in-scala.aspx

scala 类中的对象是类

scala 类中的对象是类_Scala中的类和对象相关推荐

  1. scala中的高阶函数_Scala中的高阶函数(HOF)

    scala中的高阶函数 Higher Order Functions (HOF) in Scala are the very core of this functional programming l ...

  2. python中迭代对象是什么_python中的迭代对象和迭代器

    一.什么是可迭代对象? 迭代是访问集合元素的一种方式.以直接作用于 for 循环的数据类型有以下几种:集合数据类型,如 list . tuple . dict . set . str 等: gener ...

  3. java中的对象是什么_Java中的对象是什么以及如何使用它?

    成为经过认证的专业Java是一种面向对象的语言.换言之,Java中的几乎所有内容都被视为一个对象.因此,在用Java编程时,应该知道用Java创建对象的所有可能方法.但在深入研究对象之前,您必须了解J ...

  4. scala中的二维数组_Scala中的多维数组

    scala中的二维数组 多维数组 (Multi-dimensional arrays) An Array that stores data in the form multidimensional m ...

  5. scala 类中的对象是类_Scala类和对象– Singleton对象,伴侣类

    scala 类中的对象是类 Earlier we learned about Scala Programming Language and it's installation on Windows a ...

  6. 从Java类到对象的创建过程都做了些啥?内存中的对象是啥样的?

    转载自   从Java类到对象的创建过程都做了些啥?内存中的对象是啥样的? 先回顾一下Java程序执行的过程: Java程序执行时,第一步系统创建虚拟机进程,然后虚拟器用类加载器Class Loade ...

  7. java定义一个点_JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point类中要定义它的三个构造函数...

    JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point类中要定义它的三个构造函数 JAVA 定义一个Point类 它的对象是指一个平面上的点(x,y),在定义Point ...

  8. python中的object是什么意思_Python object类中的特殊方法代码讲解

    python版本:3.8class object: """ The most base type """ # del obj.xxx或del ...

  9. java铃声类_MediaPlayer.setDataSource中的java.lang.IllegalStateException,使用铃声类

    我有一个用户(Samsung Galaxy S5,Android 4.4)报告的崩溃,我不明白发生了什么.这似乎是可以吸收的,但也许有些人遇到了同样的问题,或类似的问题.MediaPlayer.set ...

最新文章

  1. 【算法】一个简单的随机森林(RF)原理
  2. oracle(thin),kettle thin方式连接oracle,MySQL、SqlServer
  3. vs2019新建android生成app,VS2017 VS2019创建离线安装包
  4. 算法岗面试前怎样高效刷题?
  5. oracle缓存怎么看,Oracle从缓存里面查找真实的执行计划
  6. 基于C#的socket编程的TCP异步实现
  7. 锻炼编程思维的小题目
  8. matlab的基本语法规则_MATLAB基础语法
  9. 整理一下CCF推荐期刊会议(A类)
  10. 高斯核与高斯核的卷积的结果还是一个高斯核的推导
  11. 基于JavaWeb的3D网上模板商城
  12. “晨光”老矣,尚能饭否?
  13. 申城最浪漫的法国普卢旺司餐厅--Bistro Latitude
  14. android应用商店完整版源码
  15. 网站使用微信网页授权,qq登录
  16. redis--bugger分析
  17. java 问号_java问号乱码解决方法
  18. 解决VAX 2210 不能识别 VS2017的问题
  19. mysql wating for_MySQL:关于Wating for Slave workers to free pending events等待
  20. C++常用函数(刷PAT甲级总结)

热门文章

  1. Python二级笔记(5)
  2. 四因素三水平正交表_做论文要用正交表?我打包送给你
  3. js禁止鼠标滑轮_js实现鼠标滑动到某个div禁止滚动
  4. 广电运通不好进吗_我可以说郑州新风的安装大部分都是垃圾吗?
  5. oracle的undo表空间不足,undo表空间不足,ORA-30036 unable to extend segment by ...
  6. mysql增加实例,MySQL的简单使用笔记:增加实例以及启动
  7. 接口实例(C#,IShape)【C#】
  8. windosw7 Hosts文件的位置
  9. FreeMarker_模板引擎_代码自动生成器_源码下载
  10. Linux Software RAID的rebuild速度。