Scala – Object Private Fields

  • date 22nd April, 2021 |
  • by Prwatech |
  • 0 Comments

In Scala like other languages java and C++, a method can get access to the private fields of all objects of its class.

For example:

use case 1:

scala> class prwa{

     private var value = 5

     def incr() {value +=4 }

     def current = value

     }

use case 2:

scala> class prwaedu{

     private var value = 2

     def incr() {value +=3 }

     def current = value

     }

use case 3:

scala> class A2{

     private var value = -3

     def incr() {value +=1 }

     def current = value

     }

0
0

Quick Support

image image