Scala 深入浅出实战经典 第7讲:Scala类的属性和对象私有字段实战详解
2015-08-14 01:42
399 查看
一、课程前导
DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。
Scala 深入浅出实战经典(1-81讲)完整视频、PPT、代码下载:
百度云盘:http://pan.baidu.com/s/1c0noOt6
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2
Scala是最为重要的大数据语言,该视频每天还在持续跟新中,预计大约有140讲,请您根据上述视频彻底掌握Scala实战技术。
《第7讲:Scala类的属性和对象私有字段实战详解》的视频地址:
酷6:http://v.ku6.com/show/_bvsoz8t5fseMzJ-i4saNg...html
51cto:http://edu.51cto.com/lesson/id-66506.html
最后,王家林老师个人的微信是18610086859
二、课程内容
注:下面的笔记源于王家林老师的第7讲:Scala类的属性和对象私有字段实战详解、Lazy的使用视频和《快速Scala》书。
第7讲:Scala类的属性和对象私有字段实战详解
1、Scala类的使用实战
2、getter与setter实战
3、对象私有属性实战
一、Scala类的实战
//没有Public,默认是Public级别Class Person{Private var age = 0 //var可改变值的,private级别,与java不同的是这个age必须赋值Def increment(){age += 1} Def current = age}Class Student{ Var age= 0 //声明一属性,默认private,与java不同,默认生成age的getter,setter,在scala对应为age的age,age_}Object HelloOOP{Def
main(args:Array[String]:Unit = {Val person = new Person()Person.increment()Println(person.current)}
二、getter与setter实战
Val student = new StudentStudent.age = 10 //调用Student类自动生成的Student.setAge,在Scala,是age_ ,来赋值Println(Student.age) //通过Student类自动生成的Student.getAge,在Scala,是age,来取值打印Class Student{ private var privateAge = 0 val name = “Scala” //自动生成final和getter,也就是只读属性
def age = privateAge}Object HelloOOP{Def main(args:Array[String]:Unit = {Val student = new Student//Student.name = 10 报错,只能读不能写Println(Student.name)}三、对象私有属性实战
Class Student{ private[this] var privateAge = 0 //类的方法只能访问自己对象的私有属性,不能访问其他对象的属性,也就是当前对象私有 val name = “Scala” //自动生成final和getter,也就是只读属性
def age = privateAge//方法可以访问这个类的所有私有字段 def isYonger(other : Student) = privateAge < other.privateAge //若privateAge设为对象私有,则报错,因为other是Student派生的对象,那么other中也有这个字段,属于other对象私有,不能被别的对象访问}
DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。
Scala 深入浅出实战经典(1-81讲)完整视频、PPT、代码下载:
百度云盘:http://pan.baidu.com/s/1c0noOt6
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2
Scala是最为重要的大数据语言,该视频每天还在持续跟新中,预计大约有140讲,请您根据上述视频彻底掌握Scala实战技术。
《第7讲:Scala类的属性和对象私有字段实战详解》的视频地址:
酷6:http://v.ku6.com/show/_bvsoz8t5fseMzJ-i4saNg...html
51cto:http://edu.51cto.com/lesson/id-66506.html
最后,王家林老师个人的微信是18610086859
二、课程内容
注:下面的笔记源于王家林老师的第7讲:Scala类的属性和对象私有字段实战详解、Lazy的使用视频和《快速Scala》书。
第7讲:Scala类的属性和对象私有字段实战详解
1、Scala类的使用实战
2、getter与setter实战
3、对象私有属性实战
一、Scala类的实战
//没有Public,默认是Public级别Class Person{Private var age = 0 //var可改变值的,private级别,与java不同的是这个age必须赋值Def increment(){age += 1} Def current = age}Class Student{ Var age= 0 //声明一属性,默认private,与java不同,默认生成age的getter,setter,在scala对应为age的age,age_}Object HelloOOP{Def
main(args:Array[String]:Unit = {Val person = new Person()Person.increment()Println(person.current)}
二、getter与setter实战
Val student = new StudentStudent.age = 10 //调用Student类自动生成的Student.setAge,在Scala,是age_ ,来赋值Println(Student.age) //通过Student类自动生成的Student.getAge,在Scala,是age,来取值打印Class Student{ private var privateAge = 0 val name = “Scala” //自动生成final和getter,也就是只读属性
def age = privateAge}Object HelloOOP{Def main(args:Array[String]:Unit = {Val student = new Student//Student.name = 10 报错,只能读不能写Println(Student.name)}三、对象私有属性实战
Class Student{ private[this] var privateAge = 0 //类的方法只能访问自己对象的私有属性,不能访问其他对象的属性,也就是当前对象私有 val name = “Scala” //自动生成final和getter,也就是只读属性
def age = privateAge//方法可以访问这个类的所有私有字段 def isYonger(other : Student) = privateAge < other.privateAge //若privateAge设为对象私有,则报错,因为other是Student派生的对象,那么other中也有这个字段,属于other对象私有,不能被别的对象访问}
相关文章推荐
- Scala 深入浅出实战经典 第6讲:Map、Tuple、Zip实战解析
- cocos2d-x 3.0 示例代码分析3:BaseTest
- ios 字节限制
- 原码 反码 补码
- JavaScript基础教程
- 数论小知识更新ING
- 为什么浏览器采用多进程模型
- css学习笔记(1)
- 如何快速将vc++的类转换为c#/cli
- MSP430应用技巧1:COFF ABI与EABI
- HDU - 2874 Connections between cities(LCA)
- ECSHOP购物流程收货人信息详细地址显示省市区
- 阿里巴巴面试专场
- HDU - 2586 How far away ?(LCA)
- ASP.NET之GridView常用方法总结
- 在Linux下编译安装PHP5.6.11(4)
- Cocos2d-x 2.0 TestCpp框架源码分析
- Java学习-025-类名或方法名应用之一 -- 调试源码
- hdu 2665 划分树
- HDU - 3394 Railway(连通分量+环)