class Creature { def range: Int = 110 val env: Array[Int] = new Array[Int](range) } class AntA extends Creature { override def range = 20 } class AntB extends Creature { override val range = 50 } //Def range is defined before primary constructor call => println(new AntA().env.size) //2 // Val range is defined after primary constructor call => println(new AntB().env.size) //0
scala 继承2
最新推荐文章于 2023-04-24 21:14:38 发布