Scala Variable Declaration

Scala variables are same as Java variables. Only syntax is slightly different.

Rules for Scala variable declaration

  • Type declaration and semicolon are optional.
  • Keyword var is used to declare the variables. Values can be reassigned.
  • Keyword val is used to define the values. Values cannot be reassigned (Same as Java’s final type)

Scala also supports multiple variable assignments in a different way than Java. Here are the examples,

Next : Refer to Method Declaration in Scala

Leave a Reply

Notify of