I am a Java developer trying to learn Class creation in Scala.
I create two separate scala files. One file contains a trait. The second file extends the trait and defines a method.
Cola.scala This contains the trait.
trait Cola
{
def fizz(): String
}
Pepsi.scala This has a class that tries to extend the trait.
class Pepsi extends Cola
{
override def fizz():String = "1 Sugar"
}
var p = new Pepsi
println( " p = " + p.fizz )
When I excecute "scala Pepsi.scala" I get the following error message:
error: not found: type Cola
class Pepsi extends Cola
Both files are in the same folder.
Please help how to resolve this? I am using Scala 2.8 I am not using an editor so that I will be forced from scratch. This is to improve my knowledge about computers.
Try compiling them both and running them like you would a java command:
scalac Cola.scala Pepsi.scala
scala -classpath . Pepsi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With