title: Scala: Matching case classes
body: <p>The following code claims that Jack is employed in construction, but Jane is yet another victim of the rough economy:</p>
  
  <pre><code>abstract class Person(name: String) {
  
    case class Student(name: String, major: String) extends Person(name)
  
    override def toString(): String = this match {
      case Student(name, major) =&gt; name + " studies " + major
      case Worker(name, occupation) =&gt; name + " does " + occupation
      case _ =&gt; name + " is unemployed"
    }
  }
  
  case class Worker(name: String, job: String) extends Person(name)
  
  object Narrator extends Person("Jake") {
    def main(args: Array[String]) {
      var friend: Person = new Student("Jane", "biology")
      println("My friend " + friend) //outputs "Jane is unemployed"
      friend = new Worker("Jack", "construction")
      println("My friend " + friend) //outputs "Jack does construction"
    }
  }
  </code></pre>
  
  <p>Why does the match fail to recognize Jane as a Student?</p>