InterviewSolution
| 1. |
What is a Trait? |
|
Answer» A trait is like a Java interface declaring a SET of methods and fields. The difference is that the members of a trait may not be abstract. If a class extends a trait, it should implement the abstract methods and fields declared by the trait. On the other hand, it may or may not override those methods having bodies. For example, trait Comparable[T] { def compare(other: T): Int; def greaterThan (other: T) = compare(other) > 0 def lessThan (other: T) = compare(other) < 0 def isEqualTo (other: T) = compare(other) == 0 } trait Loggable { def LOG(out:PRINTWRITER) }
|
|