# 密封類別（Sealed class）

``case class Point(x: Int, y: Int)case class Circle(p: Point, r: Int)case class Cylinder(c: Circle, h: Int)``

``def what(a: Any) = a match {    case Point(_, _)    => "點"    case Circle(_, _)   => "圓"    case Cylinder(_, _) => "柱"}``

``def what(a: Any) = a match {    case Point(_, _)    => "點"    case Cylinder(_, _) => "柱"}``

``sealed abstract class Drawingcase class Point(x: Int, y: Int) extends Drawingcase class Circle(p: Point, r: Int) extends Drawingcase class Cylinder(c: Circle, h: Int) extends Drawing``

``sealed trait Drawingcase class Point(x: Int, y: Int) extends Drawingcase class Circle(p: Point, r: Int) extends Drawingcase class Cylinder(c: Circle, h: Int) extends Drawing``

``def what(d: Drawing) = d match {    case Point(_, _)    => "點"    case Cylinder(_, _) => "柱"}``

warning: match is not exhaustive!
missing combination         Circle

def what(d: Drawing) = d match {
^

``def what(d: Drawing) = d match {    case Point(_, _)    => "點"    case Circle(_, _)   => "圓"    case Cylinder(_, _) => "柱"}``

``def what(d: Drawing) = d match {    case Point(_, _)    => "點"    case Cylinder(_, _) => "柱"    case _              => "" // 作你想作的事，或者丟出例外}``

``def what(d: Drawing) = (d: @unchecked) match {    case Point(_, _)    => "點"    case Cylinder(_, _) => "柱"}``