首页 > 其他 > 详细

scala 第7讲 类的属性和对象的私有字段

时间:2015-08-15 00:09:45      阅读:178      评论:0      收藏:0      [点我收藏+]

温故而知新 之scala第7讲类的属性和对象私有字段
百度云盘连接http://yun.baidu.com/share/home?uk=4013289088#category/type=0
class Person {
private var age = 0
def increment(){age += 1}
def current = age


}

class Student{
private var privateAge = 0
val name = "Scala"
def age = privateAge

def isYounger(other: Student) = privateAge < other.privateAge
}

object HelloOOP {

def main(args: Array[String]): Unit = {
val person = new Person()
person.increment()
person.increment()
println(person.current)
//
// val student = new Student
// student.age = 10
// println(student.age)

val student = new Student
println(student.name)

}

}

scala 第7讲 类的属性和对象的私有字段

原文:http://www.cnblogs.com/trgaaaaa/p/4731485.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!