class Rational(n:Int,d:Int) { val number = n val denom = d def this(n:Int) = this(n,1) def add(that:Rational):Rational = { new Rational( number * that.denom + denom * that.number, denom * that.denom) } def sub(that:Rational) : Rational = { new Rational(number * that.denom - that.number * denom , denom * that.denom) } def +(that:Rational):Rational = { new Rational( number * that.denom + denom * that.number, denom * that.denom) } def +(that:Int):Rational = { this.+(new Rational(that)) } implicit def intToRational(n:Int)= new Rational(n) override def toString():String = number + "/" + denom } ---------------------------------------------------------------------------------------- object RationalMain { def main(args:Array[String]) { val x = new Rational(1,3) val y = new Rational(2) val z = 2.+(x) // shows error like cannot be applied to (Rational) println(z) } }