There are two keywords which define the accessors functions: a getter and setter for the fullName property. When the property is accessed, the return value from the getter is used. When a value is set, the setter is called and passed the value that was set.
Example: This example describes the use of lang() property to get the value of language property.
Example: This example describes the use of lang() property to set the value of language property.
Note: Getters and Setters are not supported in Internet Explorer 8.
Reasons to use Getters and Setters:
- The syntax for properties and methods are equal.
- Used for doing things behind-the-scenes.
- They can secure better data quality.
- The syntax of this are simpler.
Data Quality: The Getters and Setters are used to securing better data quality.
In the given example below, using the lang property, the lower case value of the language is returned.
Example: This example use lang property and it returns the lower case value of the language.
- Overriding Accessors and Mutators in Scala
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.