Scala allows us to define anonymous inner classes. The syntax is very similar to the one we know in Java.
object Demo { def main(args:Array[String]):Unit = { val ob = new MyStack[Int](0) { def data:Nothing = throw new Exception("empty stack"); } } } abstract class MyStack[T](size:Int) { def data:T; }
The following video clip overviews this code sample.