trait HelloTrait { def sayHello(name: String) } trait MakeFriendsTrait { def makeFriends(p: Person) } class Person(val name: String) extends HelloTrait with MakeFriendsTrait with Cloneable with Serializable { def sayHello(name: String): Unit = println("Hello, " + name) def makeFriends(p: Person): Unit = println("Hello, my name is " + name + ", your name is " + p.name) } val person = new Person("0mifang") val fensi = new Person("fensi") fensi.sayHello("0mifang") person.makeFriends(fensi)
trait Logger { def log(message: String) = println(message) } class Person(val name: String) extends Logger { def makeFriends(p: Person) { 。。。
。。。ide