In this blog, we will discuss about Scala fields and methods. As we know that fields in any language used to store the information and methods are use to define the behavior of the object. Let’s discuss more about both of them in detail.

What are fields in Scala?

Fields are basically keeping the state of an object. Unlike in Java, Scala fields are of two types i.e Mutable fields and immutable fields. So we can declare mutable fields by using the keyword **var **and immutable fields by using the keyword val

What are immutable fields in Scala?

In this paragraph, we will discuss more about immutable fields. Immutable means that you can’t change (mutate) your variables. It means you cannot reassign the value once you initialize it. It is the best practice to use always immutable fields because it won’t lead to concurrency issues. val is the keyword used to define immutable fields. Below is an example of how to define an immutable field in Scala.

Now let’s see the byte code representation of the above example and what compiler do when we define any field with val keyword.

#scala #method

Scala: Field And Method
1.10 GEEK