matiit
matiit

Reputation: 8017

Scala, importing class

I have two files:

logic.scala and main.scala

logic.scala contains one class and main.scala have one class with method main (to run it). And I want to import a class from logic.scala and use this class to create object(s) and work with them.
How to import and compile it in proper way?

Upvotes: 35

Views: 56749

Answers (1)

Vasil Remeniuk
Vasil Remeniuk

Reputation: 20627

  • logic.scala code
package logic

class Logic{

  def hello = "hello"

}
  • main.scala code
package runtime

import logic.Logic  // import

object Main extends Application{

  println(new Logic hello) // instantiation and invocation

}
  • compile the files with scalac
scalac *.scala
  • run your application with scala
scala -cp . runtime.Main

Upvotes: 54

Related Questions