码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-08-15 00:10:25      阅读:191      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!