Determine the class of a Scala object Last Updated : 02 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report To determine the class of a Scala object we use getClass method. This method returns the Class details which is the parent Class of the instance. Below is the example to determine class of a Scala object. Calling method with argument - Example #1: Scala // Scala program to determine the class of a Scala object // Creating object object Geeks { // Using getClass method def printClass(num: Int*) { println("class: " + num.getClass) } // Main method def main(args: Array[String]) { // Calling parameter with parameter printClass(4, 2) } } Output: class: class scala.collection.mutable.WrappedArray$ofInt In above example, Calling the printClass method with parameter demonstrates the class Scala. Calling method without argument - Example #2: Scala // Scala program to determine the class of a Scala object // Creating object object Geeks { // Using getClass method def printClass(num: Int*) { println("class: " + num.getClass) } // Main method def main(args: Array[String]) { // Calling method without parameter printClass() } } Output: class: class scala.collection.immutable.Nil$ In above example, Calling the printClass method without parameter demonstrates the class Scala. With additional get* methods - Example #3: Scala // Scala program to show how // the additional get* methods work sealed trait Person class Boy extends Person class Girl extends Person // Creating object object Person { // factory method def getPerson(s: String): Person = if (s == "Boy") new Boy else new Girl } object ObjectCastingTest extends App { val person = Person.getPerson("Boy") // class object_casting.Boy println("person: " + person.getClass) // object_casting.Boy println("person: " + person.getClass.getName) // Boy println("person: " + person.getClass.getSimpleName) // object_casting.Boy println("person: " + person.getClass.getCanonicalName) } Output: person: class Boy person: Boy person: Boy person: Boy Above code show how the additional get* methods getName, getSimpleName, and getCanonicalName work. Comment More infoAdvertise with us Next Article Determine the class of a Scala object D DivyaPareek Follow Improve Article Tags : Python Scala Scala-OOPS Practice Tags : python Similar Reads Class and Object in Scala Classes and Objects are basic concepts of Object Oriented Programming which revolve around the real-life entities. Class A class is a user-defined blueprint or prototype from which objects are created. Or in other words, a class combines the fields and methods(member function which defines actions) 5 min read Object Casting in Scala In order to cast an Object (i.e, instance) from one type to another type, it is obligatory to use asInstanceOf method. This method is defined in Class Any which is the root of the scala class hierarchy (like Object class in Java). The asInstanceOf method belongs to concrete value members of Class An 2 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 Generic Classes in Scala In Scala, forming a Generic Class is extremely analogous to the forming of generic classes in Java. The classes that takes a type just like a parameter are known to be Generic Classes in Scala. This classes takes a type like a parameter inside the square brackets i.e, [ ]. This classes are utilized 3 min read Scala | Case Class and Case Object Explanation of Case Class A Case Class is just like a regular class, which has a feature for modeling unchangeable data. It is also constructive in pattern matching. It has been defined with a modifier case, due to this case keyword, we can get some benefits to stop oneself from doing a sections of 5 min read Like