5 类 5.1 改进5.1节的Counter类,让它不要在Int.MaxValue时变成负数 class Count{ private var value = Int.MaxValue else value } def current = value } 5.2 编写一个BankAccount类,增加deposit和withdraw方法,和一个仅仅读的balance属性 ){ def deposit(){} def withdraw(){} } 5.3 编写一个Time类,增加仅仅读属性hou…
嵌套类: class Human { class Student{ val age = 10 } } object ClassDemo { def main(args: Array[String]): Unit = { val h = new Human val s = new h.Student println(s.age) } } 有时会遇到这种情况: class Human { class Student { def addS(s: Student) = { val ab = new Ar…