class Station { val size = 100 val spots = new Array[String](size) }
class Park extends Station { override val size = 20 }
object Client extends App{ val park = new Park println(park.spots.size) }
public class Station { int size; String[] spots; public Station(){ size = 100; spots = new String[getSize()]; } int getSize(){ return size; } } public class Park extends Station { int size; public Park(){ size = 20; } @Override int getSize() { return size; } }
class Station { val size = 100 lazy val spots = new Array[String](size) }
class Park(override val size:Int = 20) extends Station { }
class Park extends {override val size = 20} with Station { }
原文地址:http://blog.csdn.net/u010256841/article/details/46008201