Creating a Class in Scala
In this lesson, we will start working with object-oriented programming and you will learn how to create your own class in Scala.
We'll cover the following
Introduction
In a previous lesson, you were introduced to classes and objects. We looked at some of Scala’s built-in classes such as Seq
. But you can make your own classes and, in this chapter, we will cover user-defined classes and learn how to write our very own classes and objects. We will pick up where we left off in the introductory lesson; it is recommended you go over the lesson once more before moving on.
Without further ado, let’s create our own Person
class.
Defining a Class
To define a class in Scala, the class
keyword is used, followed by an identifier (class name) of our choosing.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy