scala中math包
Scala软件包 (Scala Packages)
In Scala, Packages are used to put classes, sub-packages, traits and other packages together. It is the namespace of code in files and directories in the Scala programming language. It is used to maintain code into folders isolating them from other members. Also, managing their access of members using access specifiers like public (when nothing is specified), package specific, protected, private.
在Scala中, 包用于将类,子包,特征和其他包放在一起。 它是Scala编程语言中文件和目录中代码的名称空间。 它用于将代码维护在文件夹中,以使其与其他成员隔离。 另外,使用访问说明符(如public(未指定任何内容),特定于包,受保护的,私有的)来管理对成员的访问。
Declaring a Package in Scala
在Scala中声明一个包
The first statement of a Scala programming is package declaration in Scala.
Scala编程的第一条语句是Scala中的程序包声明。
Syntax:
句法:
package package_name
You can also define packages in some different ways in Scala,
您还可以在Scala中以某些不同的方式定义包,
package x.y.z
// or
package x
package y
package z
Scala中的软件包工作 (Working of packages in Scala)
Packages are files that are used to encapsulate data and storing data into files. Packages are similar to the directory structure. It will locate classes that are directories in easy-access locations.
包是用于封装数据并将数据存储到文件中的文件。 软件包类似于目录结构。 它将在易于访问的位置找到属于目录的类。
The naming convention is reverse order for packages i.e. com.includehelp.scala.
软件包的命名约定是相反的顺序,即com.includehelp.scala 。
Adding Members to a Package in Scala
在Scala中将成员添加到包中
In Scala, new members can be added to a package. Members like classes, subclasses, traits, objects, sub-packages. In Scala, you can add different files in the same package.
在Scala中,可以将新成员添加到包中。 成员喜欢类,子类,特征,对象,子包。 在Scala中,您可以在同一包中添加不同的文件。
Syntax:
句法:
package bike
class BMW {
val GS 310r
}
Example:
例:
// package bike has other classes like harley, etc.
package bike
class BMW {
val bike_name;
def display_name(){}
}
object MyClass {
def main(args: Array[String]) {
val gs310r = new BMW();
}
}
Using packages in Scala
在Scala中使用软件包
Packages are used to import members in Scala programming. The import keyword is used to add members in Scala.
包用于在Scala编程中导入成员。 import关键字用于在Scala中添加成员。
Example:
例:
// package bike has other classes like harley, etc.
import bike
object MyClass {
def main(args: Array[String]) {
val gs310r = new BMW();
val street750 = new harley();
}
}
scala中math包