Guest User

Untitled

a guest
Sep 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. constructors in scala (primary/auxiliary/default primary)
  2. class Employee(val name: String, var salary: Double) {
  3. def this() { this("John Q. Public", 0.0) }
  4. }
  5.  
  6. class Employee(n: String = "John Q. Public", s: Double = 0.0) {
  7. val name = n
  8. var salary = s
  9. }
  10.  
  11. class Employee(n: String, s: Double) {
  12. def this() = this("John Q. Public", 0.0)
  13. val name = n
  14. var salary = s
  15. }
  16.  
  17. class Employee {
  18. private var _name = "John Q. Public"
  19. var salary = 0.0
  20. def this(n: String, s: Double) { _name = n; salary = s; }
  21. def name = _name
  22. }
Add Comment
Please, Sign In to add comment