Scala, importing class

前端 未结 1 1492
暗喜
暗喜 2020-12-28 13:52

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

1条回答
  •  醉梦人生
    2020-12-28 14:11

    • 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
    

    0 讨论(0)
提交回复
热议问题