I am following the Scala course from Coursera and I have implemented the follwong class:
class Rational(x: Int, y: Int) {
def numer = x;
def denom = y;
def add(that: Rational) =
new Rational(
numer * that.denom + that.numer * denom,
denom * that.denom)
override def toString = numer + "/" + denom;
def main(args: Array[String]){
val x = new Rational(1, 2);
x.numer;
x.denom;
}
}
However, I get many compilation errors. The first of them appears on the first line:
Multiple markers at this line:
self constructor arguments cannot reference unconstructed this
constructor Rational#97120 is defined twice conflicting symbols both originated in file '/Users/octavian/workspace/lecture2/src/ex3.sc'
x is already defined as value x#97118
y is already defined as value y#97119
The file containing the code is called
Rational.scala
Why does this error appear?