fork download
  1. object CaseClassInheritance {
  2. abstract class Person {
  3. def name: String
  4. def age: Int
  5. // address and other properties
  6. // methods (ideally only accessors since it is a case class)
  7. def getName(): String = {
  8. return name
  9. }
  10. }
  11.  
  12. case class Employer(val name: String, val age: Int, val taxno: Int)
  13. extends Person
  14.  
  15. case class Employee(val name: String, val age: Int, val salary: Int)
  16. extends Person
  17.  
  18. case class PersonA(val name: String, val age: Int, val salary: Int) extends Person
  19.  
  20. def main(args: Array[String]) {
  21. val p = PersonA("Senthil",10,42)
  22. println(p.getName)
  23. }
  24. }
  25.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/opt/scala/bin/scalac: line 50: /dev/null: Permission denied
spoj: The program compiled successfully, but Main.class was not found.
      Class Main should contain method: def main(args: Array[String]).
stdout
Standard output is empty