title: Scala - override a class method in a trait
body: <p>I'm new to Scala (came from Ruby world).</p>
  
  <p>And I was curious about "traits" concept in Scala (which should be ~similar to modules in ruby, if I understand it correctly).</p>
  
  <p>And here's a use case.</p>
  
  <p>Suppose I have a class called <code>User</code> defined like this:</p>
  
  <pre><code>class User {
      def password() : String = "generating a password (default)"
  }
  </code></pre>
  
  <p>And suppose I have a trait <code>SecurePasswords</code> using which I would like to "override" the password method defined in the <code>User</code> class.</p>
  
  <pre><code>trait SecurePasswords {
      def password() : String = "generating a secure password (non-default)"
  }
  </code></pre>
  
  <p>And, suppose, I want it to be applicable to instances of the <code>User</code> class and not to the entire class itself.</p>
  
  <pre><code>val a = new User
  val b = new User with SecurePasswords
  
  a.password() # generating a password (default)
  b.password() # generating a secure password (non-default)
  </code></pre>
  
  <p>Now this is an ideal output that I would expect, however, I get different errors like "<code>anonymous class inherits conflicting members ... (Note: this can be resolved declaring etc etc ...)</code>"</p>
  
  <p>Can this be done in Scala or I'm asking too much / doing something really weird?
  Is it possible to do w/o any additional class definitions, like <code>UserWithSecurePassword extends User</code></p>
  
  <p>Thank you all in advance!</p>
  
  <p>P.S In case you are wondering "why?", just assume that system would contain a lot of entities that require password (and, potentially, secure password), so the trait could be used in a lot of places.</p>