| 1. |
What Is Diamond Problem? How Scala Solves Diamond Problem? |
|
Answer» A Diamond Problem is a Multiple Inheritance problem. Some people calls this problem as Deadly Diamond Problem. In Scala, it OCCURS when a Class extends more than one Traits which have same method definition. Unlike Java 8, Scala solves this diamond problem automatically by following some rules defined in Language. Those rules are called “Class LINEARIZATION”. Example:- trait A{ Here OUTPUT is “From C.display” form trait C. Scala Compiler reads “extends B with C” from right to left and takes “display” method definition from lest most trait that is C. A Diamond Problem is a Multiple Inheritance problem. Some people calls this problem as Deadly Diamond Problem. In Scala, it occurs when a Class extends more than one Traits which have same method definition. Unlike Java 8, Scala solves this diamond problem automatically by following some rules defined in Language. Those rules are called “Class Linearization”. Example:- trait A{ Here output is “From C.display” form trait C. Scala Compiler reads “extends B with C” from right to left and takes “display” method definition from lest most trait that is C. |
|