Calling A Super Class Constructor in Scala Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisite - Scala ConstructorsIn Scala, Constructors are used to initialize an object's state and are executed at the time of object creation. There is a single primary constructor and all the other constructors must ultimately chain into it. When we define a subclass in Scala, we control the superclass constructor that is called by its primary constructor when we define the extends portion of the subclass declaration. With one constructor: An example of calling a super class constructor Example: Scala // Scala program to illustrate // calling a super class constructor // Primary constructor class GFG (var message: String) { println(message) } // Calling the super class constructor class Subclass (message: String) extends GFG (message) { def display() { println("Subclass constructor called") } } // Creating object object Main { // Main method def main(args: Array[String]) { // Creating object of Subclass var obj = new Subclass("Geeksforgeeks"); obj.display(); } } Output: Geeksforgeeks Subclass constructor called In the above example, the subclass is defined to call the primary constructor of the GFG class, which is a single argument constructor that takes message as its parameter. When defining a subclass in Scala, one controls the Superclass constructor that's called by the Subclass's primary constructor when defining the extends segment of the Subclass declaration.With multiple constructors : In a case with the Superclass having multiple constructors, any of those constructors can be called using the primary constructor of the Subclass. For Example, in the following code, the double argument constructor of the Superclass is called by the primary constructor of the Subclass using the extends clause by defining the specific constructor.Example: Scala // Scala program to illustrate // calling a specific super class constructor // Primary constructor (1) class GFG (var message: String, var num: Int) { println(message+num) // Auxiliary constructor (2) def this (message: String) { this(message, 0) } } // Calling the super class constructor with 2 arguments class Subclass (message: String) extends GFG (message, 3000) { def display() { println("Subclass constructor called") } } // Creating object object GFG { // Main method def main(args: Array[String]) { // Creating object of Subclass var obj = new Subclass("Article count "); obj.display(); } } Output: Article count 3000 Subclass constructor called We can call the single argument constructor here, By default another argument value will be 0. Example: Scala // Scala program to illustrate // calling a specific super class constructor // Primary constructor (1) class GFG (var message: String, var num: Int) { println(message + num) // Auxiliary constructor (2) def this (message: String) { this(message, 0) } } // Calling the superclass constructor with 1 arguments class Subclass (message: String) extends GFG (message) { def display() { println("Subclass constructor called") } } // Creating object object GFG { // Main method def main(args: Array[String]) { // Creating object of Subclass var obj = new Subclass("Article Count "); obj.display(); } } Output: Article Count 0 Subclass constructor called Comment More info V vishodushaozae Follow Improve Article Tags : Scala Scala Scala-Constructor 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