Example
import java.io._
class Point(val xc: Int, val yc: Int) {
   var x: Int = xc
   var y: Int = yc
   
   def move(dx: Int, dy: Int) {
      x = x + dx
      y = y + dy
      println ("Point x location : " + x);
      println ("Point y location : " + y);
   }
}
object Demo {
   def main(args: Array[String]) {
      val pt = new Point(10, 20);
      // Move to a new location
      pt.move(10, 10);
   }
}
Save the above program in Demo.scala. The following commands are used to compile and execute this program.
Command
\>scalac Demo.scala
\>scala Demo
Output
Point x location : 20
Point y location : 30