标签:
温故而知新 之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)
}
}
标签:
原文地址:http://www.cnblogs.com/trgaaaaa/p/4731485.html