To define a class in Scala, the class keyword is used, followed by an identifier (class name) of our choosing.
svg viewer
Let’s map the syntax to our Person class.
1
class Person
At this point, our class doesn’t have any properties or methods.
Defining the Properties of a Class
Properties are variables and in Scala, they are called fields. They are also known as instance variables because every instance gets its own set of the variables.
All the members of a class, including fields, are placed in a block.
svg viewer
Our Person class has three fields: name, gender, and age.