InterviewSolution
Saved Bookmarks
| 1. |
What are case classes in Scala? |
|
Answer» Scala CASE classes are like regular classes except for the fact that they are good for MODELING immutable data and serve as useful in pattern matching. Case classes include public and immutable parameters by default. These classes support pattern matching, which makes it easier to write logical code. The following are some of the characteristics of a Scala case class:
Syntax: case class className(parameters)Example: case class Student(name:String, age:Int) object MainObject { def main(args:Array[String]) { var c = Student(“AARAV”, 23) println("Student name:" + c.name); println("Student age: " + c.age); } }Output: Student Name: Aarav Student Age: 23 |
|