What is the difference between val and var in Scala?



What is the difference between val and var in Scala?..

Answer / Prakash Kumar Rathaur

In Scala, val and var are used to declare variables. The main difference lies in their immutability: val declares a constant that cannot be reassigned, while var can be reassigned. Once assigned, the value of a val remains unchanged throughout its lifetime, whereas the value of a var may change multiple times.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Scala Interview Questions

List the default imports are available in scala language?

1 Answers  


Explain either/left/right design pattern in scala?

1 Answers  


What is formula tail in scala?

1 Answers  


What is the final class in scala?

1 Answers  


Explain if-else-if terminology?

1 Answers  


What is the use of ‘yield’ keyword in Scala’s for-comprehension construct?

1 Answers  


what are the features of scala?

1 Answers  


How is the scala code compiled?

1 Answers  


Why scala is faster than java?

1 Answers  


What is Scala?

1 Answers  


How scala is different from java?

1 Answers  


What is exception propagation in scala?

1 Answers  


Categories