fork download
  1. object Main extends App {
  2. class Parent {
  3. def entry(): Unit =
  4. // this is a virtual dispatch, so it can invoke different
  5. // implementation of "printer" method than println("I'm Parent")
  6. // `this` reference is of type Parent, but real type can be Child
  7. this.printer()
  8.  
  9. def printer(): Unit =
  10. println("I'm Parent")
  11. }
  12.  
  13. class Child extends Parent {
  14. override def printer(): Unit =
  15. println("I'm Child")
  16. }
  17.  
  18. new Child().entry()
  19. }
  20.  
Success #stdin #stdout 0.39s 2181632KB
stdin
Standard input is empty
stdout
I'm Child