1.

What do you mean by class parameters in Scala?

Answer»

In Scala, while declaring a class, sometimes we SPECIFY some PARAMETERS which are mandatory to pass while instantiating an object of that type. These parameters are called the class parameters.

As the body of the class plays the ROLE of the primary CONSTRUCTOR in Scala, these parameters actually define its arguments. If we declare the parameters with val or var, they become a member of the class. In the example below, id, name, and salary are the class parameters for the Employee class. Here, id and name are the members of the class, but the salary is not.

class Employee(val id:Long, val name:String, salary:Int)


Discussion

No Comment Found