test source code:
/* 2015-09-14 15:36PM */
package test {
class Counter {
private var value = 0 // or else value will be treated as NaN
def add() { value += 1 } // default: public
def current = value // here I define a method without (),
// this forces the method caller to also call it without ()
def printArgs(args: Array[String]): Integer = {
args.foreach(println)
return args.length
}
var public_value = 1
}
object jerry extends App {
val counter = new Counter
println("current: " + counter.current);
val array = Array("1","2","3")
println(counter.printArgs(array))
counter.public_value = 41
println(counter.public_value)
}
}
由此可见,getter和setter并非被命名为getXXX和setXXX
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。