title: Anonymous Subclass in Scala
body: <p>I am trying to understand Anonymous subclass in Scala. I have written the below code:</p>
  
  <pre><code>package com.sudipta.practice.chapter8
  
  class Person(val name: String) {
    def printMyName = println("Name: " + name)
  }
  
  class AnonymousSubclass(val name: String) {
      val anonymousSubclass = new Person(name){
        def sayHello = "Hello, " + name
        def sayBye = "Bye, " + name
        override def printMyName = println("My name is: " + name)
      }
  
  }
  
  object testPerson extends App {
  
    def printAnonDetails (myObject: AnonymousSubclass) = {
      myObject.anonymousSubclass.printMyName
    }
  
    val personObject = new Person("Sudipta")
    personObject.printMyName
  
    val anonObject = new AnonymousSubclass("Sudipta")
  
    printAnonDetails(anonObject)
  }
  </code></pre>
  
  <p>But what I am not able to understand what are the usages/advantages of Anonymous Subclass in Scala. If you have any points, please share here. Thanks.</p>
  
  <p>Regadrs,
  Sudipta</p>