Scala | Trait Mixins Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report We can extend several number of scala traits with a class or an abstract class that is known to be trait Mixins. It is worth knowing that only traits or blend of traits and class or blend of traits and abstract class can be extended by us. It is even compulsory here to maintain the sequence of trait Mixins or else the compiler will throw an error. Note: The Mixins traits are utilized in composing a class. A Class can hardly have a single super-class, but it can have numerous trait Mixins. The super-class and the trait Mixins might have identical super-types. Now, lets see some examples. Extending abstract class with trait Example : Scala // Scala program of trait Mixins // Trait structure trait Display { def Display() } // An abstract class structure abstract class Show { def Show() } // Extending abstract class with // trait class CS extends Show with Display { // Defining abstract class // method def Display() { // Displays output println("GeeksforGeeks") } // Defining trait method def Show() { // Displays output println("CS_portal") } } // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating object of class CS val x = new CS() // Calling abstract method x.Display() // Calling trait method x.Show() } } Output: GeeksforGeeks CS_portal Here, the correct order of Mixins is that, we need to extend any class or abstract class first and then extend any trait by using a keyword with. Extending abstract class without trait Example : Scala // Scala program of trait Mixins // Trait structure trait Text { def txt() } // An abstract class structure abstract class LowerCase { def lowerCase() } // Extending abstract class // without trait class Myclass extends LowerCase { // Defining abstract class // method def lowerCase() { val y = "GEEKSFORGEEKS" // Displays output println(y.toLowerCase()) } // Defining trait method def txt() { // Displays output println("I like GeeksforGeeks") } } // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating object of 'Myclass' // with trait 'Text' val x = new Myclass() with Text // Calling abstract method x.lowerCase() // Calling trait method x.txt() } } Output: geeksforgeeks I like GeeksforGeeks Thus, from this example we can say that the trait can even be extended while creating object. Note: If we extend a trait first and then the abstract class then the compiler will throw an error, as that is not the correct order of trait Mixins. Comment More info N nidhi1352singh Follow Improve Article Tags : Scala Scala scala-traits Explore OverviewScala Programming Language3 min readIntroduction to Scala7 min readSetting up the environment in Scala3 min readHello World in Scala2 min readBasicsScala Keywords2 min readScala Identifiers3 min readData Types in Scala3 min readVariables in Scala3 min readControl StatementsScala | Decision Making (if, if-else, Nested if-else, if-else if)5 min readScala | Loops(while, do..while, for, nested loops)5 min readBreak statement in Scala3 min readScala | Literals4 min readOOP ConceptsClass and Object in Scala5 min readInheritance in Scala5 min readOperators in Scala11 min readScala Singleton and Companion Objects3 min readScala Constructors4 min readScala | Polymorphism5 min readScala | Multithreading3 min readScala this keyword2 min readMethodsScala | Functions - Basics3 min readAnonymous Functions in Scala2 min readScala | Closures3 min readRecursion in Scala4 min readMethod Overloading in Scala5 min readMethod Overriding in Scala8 min readLambda Expression in Scala4 min readScala Varargs2 min readStringsScala String4 min readScala | String Interpolation3 min readScala | StringContext2 min readRegular Expressions in Scala5 min readStringBuilder in Scala4 min readScala PackagesPackages In Scala4 min readScala | Package Objects3 min readChained Package Clauses in Scala3 min readFile Handling in Scala3 min readScala TraitScala | Traits7 min readScala | Sealed Trait4 min readScala | Trait Mixins3 min readTrait Linearization in Scala5 min readCollectionsScala Lists5 min readScala ListBuffer6 min readListSet in Scala6 min readScala Map5 min readScala | Arrays6 min readScala | ArrayBuffer4 min readScala | Tuple5 min readSet in Scala | Set-13 min readSet in Scala | Set-27 min readBitSet in Scala5 min readHashSet In Scala4 min readStack in Scala3 min readHashMap in Scala3 min readTreeSet in Scala4 min readIterators in Scala5 min readScala | Option3 min read Like