scala - Cannot compile example -


i have class:

 class rational(n:int, d:int) {   require(d!=0)    private val g = gcd(n.abs, d.abs)    val numer = n/g   val denom = d/g    def this(n: int) = this(n, 1);    def add(that:rational): rational = new rational(numer * that.denom + that.numer * denom, denom * that.denom)    override def tostring = numer+"/"+denom;    private def gcd(a: int, b: int): int = if(b==0) else gcd(b, % b) } 

and test class:

import rational  object test extends app {   val x = new rational(1/2)   println("hello"); } 

i'm trying compile them using

scalac test.scala rational.scala 

but following error:

test.scala:3: error: '.' expected ';' found. object test extends app { ^ 1 error found 

can guide me why not compiling. basic error

import rational not valid syntax (because it's class)

as in default package, don't need import anyway


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -