scala学习笔记:理解类继承

scala> import scala.reflect._
import scala.reflect._

scala> class Person(@BeanProperty var name: String, val gender: Boolean=true){}
defined class Person

scala> val p = new Person("bluejoe")
p: Person = Person@5905edf2

scala> p.setName("yahoo")

scala> p.getName
res1: String = yahoo

scala> p.name
res2: String = yahoo

scala> class Man(val name2: String) extends Person(name2){}
defined class Man

scala> val m = new Man("bluejoe")
m: Man = Man@5ae63954

scala> m.name2
res3: String = bluejoe

scala> m.name
res4: String = bluejoe

scala> m.setName("alex")

scala> m.name2
res6: String = bluejoe

scala> 

posted on 2015-02-09 20:55  白乔  阅读(146)  评论(0编辑  收藏  举报

导航