当前位置:网站首页>Scala advanced_ Member access modifier
Scala advanced_ Member access modifier
2022-06-27 06:20:00 【Big data interview classic】
Access modifier
and Java equally ,scala You can also access the modifier , To control whether member variables and member methods can be accessed .
Definition
Java Access control in , The same applies scala, You can add... Before a member private/protected Keyword to control the visibility of members . But in scala in , No, public keyword , Anything not marked as private or protected All members are public
Case study
- Define a Person class
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-vq1JjDij-1581824772468)(assets/1557664595693.png)] - stay main Method , Test for access to private members
Reference code
object _02AccessDemo {
class Person {
// Define private member variables
private var name:String = _
private var age:Int = _
def getName() = name
def setName(name:String) = this.name = name
def getAge() = age
def setAge(age:Int) = this.age = age
// Private member definition method
private def getNameAndAge = {
name -> age
}
}
def main(args: Array[String]): Unit = {
val person = new Person
person.setName(" Zhang San ")
person.setAge(10)
println(person.getName())
println(person.getAge())
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
边栏推荐
猜你喜欢

Assembly language - Wang Shuang Chapter 11 flag register - Notes

POI 替换docx中的文字和图片

程序猿学习抖音短视频制作

Thinking technology: how to solve the dilemma in work and life?
软件测试年终总结报告模板

thrift

Distribution gaussienne, régression linéaire, régression logistique

C Primer Plus 第11章_字符串和字符串函数_代码和练习题

Gaussian distribution, linear regression, logistic regression

JVM class loading mechanism
随机推荐
表单校验 v-model 绑定的变量,校验失效的解决方案
Jump details of item -h5 list, and realize the function of not refreshing when backing up, and refreshing when modifying data (record scroll bar)
Assembly language - Wang Shuang Chapter 3 notes and experiments
使用 WordPress快速个人建站指南
openresty使用文档
JVM overall structure analysis
JVM class loading mechanism
1317. 将整数转换为两个无零整数的和
MATLAB快速将影像的二维坐标转换为经纬度坐标
【QT小点】QT下载链接
Proxy reflect usage details
Software testing year end summary report template
JVM object composition and storage
Altium designer 19 device silk screen label position shall be placed uniformly in batches
树莓派4B上运行opcua协议DEMO接入kubeedge
Add widget on qlistwidgetitem
Block level elements & inline elements
The restart status of the openstack instance will change to the error handling method. The openstack built by the container restarts the compute service method of the computing node and prompts the gi
An Empirical Evaluation of In-Memory Multi-Version Concurrency Control
Dev++ environment setting C language keyword display color