title: scala: defining a trait and referencing the corresponding companion object
body: <p>I'm trying to define a trait that uses the corresponding companion object, that is, the componion object of the class using the trait.</p>
  
  <p>for example, I have:</p>
  
  <pre><code>:paste
  
  class Parent {
    def callMyCompanion = print(Parent.salute)
  }
  
  object Parent {
    def salute = "Hello from Parent companion object"
  }
  
  class Child extends Parent {
  
  }
  
  object Child {
    def salute = "Hello from Child companion object"
  }
  </code></pre>
  
  <p>And then I create a parent object:</p>
  
  <pre><code>scala&gt; val p = new Parent()
  p: Parent = Parent@1ecf669
  
  scala&gt; p.callMyCompanion
  Hello from Parent companion object
  </code></pre>
  
  <p>But with a child:</p>
  
  <pre><code>scala&gt; val c = new Child()
  c: Child = Child@4fd986
  
  scala&gt; c.callMyCompanion
  Hello from Parent companion object
  </code></pre>
  
  <p>I'd like to get: Hello from Child companion object</p>
  
  <p>How can I achieve it???</p>
  
  <p>-- edit to clarify</p>
  
  <p>Thanks for your responses, but in this case callMyCompanion is a dummy method I created just to explain myself, I'm trying to reuse the parent method without having to override it in every class that implements it... </p>
  
  <p>The solution I've found so far was to implement an instance method that uses the companion obejct...</p>