Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.66 KB | None | 0 0
  1. package DPTest
  2.  
  3. trait Account {
  4.     def account_type: String
  5.     def getType(): String
  6.     def printHistory() = {}
  7. }
  8.  
  9. class CheckingAccount(accountType: String) extends Account{
  10.     override def printHistory(): Unit = {
  11.         print("Test " + this.getType() + " history")
  12.     }
  13.  
  14.     override def getType(): String = {
  15.         account_type
  16.     }
  17.  
  18.     override def account_type: String = accountType
  19. }
  20.  
  21. trait OnlineAccount extends Account{
  22.     abstract override def getType(): String = {
  23.         "online " + super.getType()
  24.     }
  25. }
  26.  
  27. object Demo extends App {
  28.     val c = new CheckingAccount("checking account") with OnlineAccount
  29.     c.printHistory()
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement