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

温故而知新 之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)

}

}

posted on 2015-08-14 23:21  trgaaaaa  阅读(277)  评论(0编辑  收藏  举报