Call a method on a Super Class in Scala Last Updated : 05 Aug, 2019 Comments Improve Suggest changes Like Article Like Report This concept is used when we want to call super class method. So whenever a base and subclass have same named methods then to resolve ambiguity we use super keyword to call base class method. The keyword "super" came into this with the concept of Inheritance. Below is the example of call a method on a superclass. Example #1: Scala // Scala program to call a method // on a superclass in Scala /* Base class ComputerScience */ class ComputerScience { def read { println("I'm reading") } def write { println("I'm writing") } } /* Subclass Scala */ class Scala extends ComputerScience { // Note that readThanWrite() is only in Scala class def readThanWrite() { // Will invoke or call parent class read() method super.read // Will invoke or call parent class write() method super.write } } // Creating object object Geeks { // Main method def main(args: Array[String]) { var ob = new Scala(); // Calling readThanWrite() of Scala ob.readThanWrite(); } } Output: I'm reading I'm writing In above example, we are calling multiple method of super class by using super keyword. Example #2: Scala // Scala program to call a method // on a superclass in Scala /* Super class Person */ class Person { def message() { println("This is person class"); } } /* Subclass Student */ class Student extends Person { override def message() { println("This is student class") } // Note that display() is only in Student class def display() { // will invoke or call current class message() method message () // will invoke or call parent class message() method super.message } } /* Creating object */ object Geeks { // Main method def main(args: Array[String]) { var s = new Student(); // Calling display() of Student s.display(); } } Output: This is student class This is person class In the above example, we have seen that if we only call method message() then, the current class message() is invoked but with the use of super keyword, message() of super class could also be invoked. Comment More infoAdvertise with us Next Article Scala Int getClass() method with example D DivyaPareek Follow Improve Article Tags : Scala Scala-OOPS Similar Reads Calling A Super Class Constructor in Scala 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 sup 3 min read Calling A Super Class Constructor in Scala 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 sup 3 min read Scala Int getClass() method with example The getClass() method is utilized to return the class of the given int number. Method Definition: (Number).getClass Return Type: It returns the class of the given number. Example #1: Scala // Scala program of Int getClass() // method // Creating object object GfG { // Main method def main(args:Array 1 min read Scala | Methods to Call Option The Option in Scala is referred to a carrier of single or no element for a stated type. When a method returns a value which can even be null then Option is utilized i.e, the method defined returns an instance of an Option, in place of returning a single object or a null. There are a few methods that 5 min read Scala | Methods to Call Option The Option in Scala is referred to a carrier of single or no element for a stated type. When a method returns a value which can even be null then Option is utilized i.e, the method defined returns an instance of an Option, in place of returning a single object or a null. There are a few methods that 5 min read Scala Char getClass() method with example The getClass() method is utilized to return the run-time class representation of the stated object. Method Definition: def getClass(): Class[Char] Return Type: It returns the class of the stated object. Example: 1# Scala // Scala program of getClass() // method // Creating object object GfG { // Mai 1 min read Like