How to declare constant variable in scala

To declare a constant variable in Scala, you can use the keyword "val" followed by the variable name, a colon, and the variable's type. Here's an example:

val myConstant: Int = 10

In this example, the constant variable is named "myConstant" and its type is specified as "Int". The value of the constant is set to 10. Once a constant variable is assigned a value, it cannot be changed.

You can also omit the type declaration if the compiler can infer the type from the assigned value. Here's an example:

val myConstant = 10

In this case, the type of "myConstant" is inferred to be "Int" based on the assigned value of 10.