Hello and welcome! In this lesson, we'll dive into Object-Oriented Programming (OOP). Object-Oriented Programming is a coding paradigm inspired by the real world. It envisages everything as an "Object" with certain properties (characteristics) and capabilities (methods). Take a football, for instance: it has properties like size and color and methods such as being able to be kicked or caught.
In Scala, a Class provides a blueprint for creating objects. It is by using these classes that we instruct Scala on how an object should look and function. We can declare a Class using the class
keyword.
Properties (characteristics) and methods (actions) that our object can possess and perform are also defined within the Class. Let's look at a simple Football
Class:
An Object is an actual instance of a Class, crafted based on the blueprint we set in our classes. Creating an Object in Scala is straightforward; we use the new
keyword followed by the class name:
Here, myFootball
is an object of the Football
Class, possessing the properties and methods we defined within the Class.
