forked from ankitsindhu/scala-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMixin.scala
52 lines (42 loc) · 1.21 KB
/
Mixin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
object Mixin {
def main(a: Array[String]) = {
val gQuota = new GeneralQuota
gQuota.printQuotaDetail
val tQuota = new TatkalQuota
tQuota.printQuotaDetail
println("Is it Special train : "+tQuota.isSpecialTrain)
val lQuota = new LadiesQuota
lQuota.printQuotaDetail
println("Is it Special train : "+lQuota.isSpecialTrain)
lQuota.printTrainInfo
val sQuota = new SeniorQuota
sQuota.printTrainInfo
}
// Abstract Class
abstract class AbsInfo {
def isSpecialTrain: Boolean
}
// Trait Object
trait MyTrain {
def printTrainInfo = {
println("Train Number : 12675")
println("Train Name : KOVAI EXPRESS")
}
}
// Normal Class
class GeneralQuota {
def printQuotaDetail = println("General Quota")
}
// Abstract class with interface method implementation
class TatkalQuota extends AbsInfo {
def printQuotaDetail = println("Tatkal Quota")
def isSpecialTrain:Boolean = false
}
// Mixin Class composition
class LadiesQuota extends AbsInfo with MyTrain {
def printQuotaDetail = println("Ladies Quota")
def isSpecialTrain:Boolean = false
}
class SeniorQuota extends GeneralQuota with MyTrain {
}
}