scala/ScalaBook/chapter-02/cell.scala

class cell (protected var  contents : Int){ // C
  def this () = this(0)
  def get() = contents
  def set(n: Int) = {
    contents = n
    println("cell")
  }
} 
 
class reCell (x : Int) extends cell(x) { // C'
  private var backup : Int = x
  override def set(n: Int) = {
    backup = this.contents
    this.contents = n
    println("reCell")
  }
  def restore() = contents = backup
}

//var C = new reCell(5)
//println(C.get())
//C.set(9)
//println(C.get())
//C.restore()
//println(C.get())

var y = new reCell(5)

def g(x: cell) =
  x.set(3)

g(y)

println(y.get)