title: Scala: How to modify some variable in class by method?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4437373/use-of-def-val-and-var-in-scala">Use of def, val, and var in scala</a>  </p>
  </blockquote>
  
  
  
  <p>I'm learning now Scala and I can't modify variable in class.</p>
  
  <pre class="lang-scala prettyprint-override"><code>class Person(name: String, var variable: Int) {
    def change() {
      variable = 42
    }
  }
  def person = new Person("name", 0)
  println(person.variable)
  person.change()
  println(person.variable)
  </code></pre>
  
  <p>And the output is:</p>
  
  <pre><code>0
  0
  </code></pre>
  
  <p>Why output contains 2 times 0? </p>
  
  <p>How I can modify variable in this Code?</p>
  
  <p>I have Scala version 2.9.1.</p>