Open In App

Getters and Setters in Scala

Getter and Setter in Scala are methods that helps us to get the value of variables and instantiate variables of class/trait respectively. Scala generates a class for the JVM with a private variable field and getter and setter methods. In Scala, the getters and setters are not named getXxx and setXxx, but they are used for the same purpose. At any time, we can redefine the getter and setter methods ourself.



Setters

Setter are a technique through which we set the value of variables of a class. Setting an variable of class is simple it can be done in two ways :-

Getters

Getters are a technique through which we get the value of the variables of a class.


Article Tags :