view chapter12/PhilosophicalTrait.scala @ 0:b316eec6fa7a draft default tip

add sample files
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 08 Jan 2013 16:41:46 +0900
parents
children
line wrap: on
line source

trait Philosophical {
    def philosphize() {
	println("I consume memory, therefore I am!")
    }
}

class Frog extends Philosphical {
 override def toString = "green"
}

class Animal
class Frog extends Animal with Philosophical {
    override def toString = "green"
}

class Rational(n: Int, d: Int) extends Ordered[Rational] {
    def compare(that: Rational) =
	(this.number * that.demon) - (that.number * this.denom)
}