adspace


What is the difference between val and var in Scala?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the latest version of scala?

93


What is the current latest version of scala? What is the major change or update in scala 2.12?

89