1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Object Oriented Programming (OOP) in Kotlin

Object Oriented Programming (OOP) in Kotlin

Objects and Classes in Kotlin
1h 31m

This course covers the concept of Object-Oriented Programming in Kotlin, which is a method of designing and implementing software. It simplifies software development and maintenance by providing concepts such as object, class, inheritance, polymorphism, abstraction, and encapsulation. This course will explore those.

Intended Audience

This course is ideal for anyone who wants to learn how to use Kotlin for developing applications on Android.


This content will take you from a beginner to a proficient user of Kotlin and so no prior experience with the programming language is required. It would, however, be beneficial to have some development experience in general.


Course GitHub repo: https://github.com/OakAcademy/Kotlin-Programming-Course/tree/main/ObjectOrientedProgramming


Well, hello friends. So, in this lesson, we're going to learn a concept of Object Oriented Programming. Now, as we talked a little bit about before, Kotlin programming language is also an Object Oriented Programming language, therefore we're going to need to learn, well, the concept of object orientation. So, what is Object Oriented Programming?

OOP or Object Oriented Programming is a method of designing and implementing software. The primary purpose of Object Oriented Programming is to increase the flexibility and maintain ability of programs. It simplifies software development and maintenance by providing some concepts. Now these concepts are object, class, inheritance, polymorphism, abstraction, and encapsulation.

Now we're going to get to these subjects each in its own time and in very, very great detail in the coming slides. But I want to start with the concept of object orientation. A class is a group of similar entities. An object can be defined as an instance of a class. Objects are often used to model real world objects that you'll find in everyday life. So, a Kotlin object is a self-contained component that consists of functions and properties. So, an object contains an address and takes up some space in memory. A class doesn't consume any memory space at all. So, the object has three characteristics. It's got state, behavior, and identity. So now, let's get into these characteristics a bit more. So, the state represents the data of an object. The behavior represents the action of an object, such as the start, stop, etc.

The identity: This is used internally by the Java Virtual Machine in order to identify each object uniquely. The value of ID, though, is not visible to the external user. So, when you think of a car, well, it's called a Ferrari, right? Its color is red. Let's say the model is 2015. So these are its state. This car starts and stops. So starting and stopping are its behavior. So let's do an example with object and class. So for instance, we'll define a car class and the properties of an object, car would be model, color, and year. An object will also execute some actions, right? Using the car, well, this car is capable of performing the following actions:  start, stop, accelerate. So now, as you can see on the slide for different values of properties; the model, the color, the year in the class car; we will get different car objects.

Cool? So, in our example, we have one class, also we have three objects. You can also create an unlimited number of objects from a class. So now, let's quickly jump and I want to show you how to define a class in Kotlin. Now, class is declared by using the word 'class'. So, this is a keyword. The class body is enclosed between curly braces. The data variables will be defined in the class and these variables are called instance variables. The action code is written in the method. All code blocks are in the class body. Variables and functions are defined in the class, and then these are members of the class. So now, when you're creating an object in Kotlin, an object is created from a class. Creating objects from any class is quite simple, my friends. The expression var here represents a variable, and then next we'll need to give a name to the object that we will create.

So in this example, I'm going to make the name of this object My Car, and then you can of course name it whatever you want. But then on the right side of the equal sign, I've got to write the name of the class that we will create the object, and that's it. So, here, the My Car object is the reference that holds the memory address of the car object. So, yes my friends, there you go. That's a brief explanation of the concept of Object Oriented Class and object concepts. So, we're going to take that forward because it's very useful information. But first we'll take a short break and then when we pick up next, we're going to talk about access modifiers in Kotlin. See you in the next video.

About the Author
Learning Paths

Mehmet graduated from the Electrical & Electronics Engineering Department of the Turkish Military Academy in 2014 and then worked in the Turkish Armed Forces for four years. Later, he decided to become an instructor to share what he knew about programming with his students. He’s currently an Android instructor, is married, and has a daughter.

Covered Topics