Key Concepts

Review core concepts you need to learn to master this subject

Classes

// A class with properties that contain default values class Student { var name = "Lucia" var semester = "Fall" var gpa = 3.95 } // Shorthand syntax with no class body class Student

A class is an object-oriented concept which resembles a blueprint for individual objects. A class can contain properties and functions and is defined using the class keyword followed by a name and optional body.

If the class does not have a body, its curly braces can be omitted.

Classes
Lesson 1 of 1
  1. 1
    Kotlin, much like Java, is an object-oriented programming language. The term, “object-oriented” refers to a language that is made up of objects and can utilize various methodologies such as [encaps…
  2. 2
    Now let’s practice writing our own classes. A Kotlin class is declared at the top of a Kotlin file, outside the main() function, with the class keyword followed by its name: class Name { // cla…
  3. 3
    Now that we’ve created our first class, let’s create an instance of it. An instance of a class resembles an object that is a member of that given class. Recall the Car class from the previous e…
  4. 4
    Looking to customize your instances? You’ve come to the right place! Kotlin classes provide us with something called a primary constructor that allows us to declare properties and initialize them w…
  5. 5
    The primary constructor does not contain any code other than the properties and their specified data types. What if we’d like to calculate a person’s age using the year they were born? We can do th…
  6. 6
    Now let’s explore how to add even more functionality to our classes with functions. A function declared within a Kotlin class is known as a member function. Member functions possess the same qu…
  7. 7
    Excellent work! In this lesson, we’ve learned the following concepts: - A class is an object-oriented concept which resembles a blueprint for individual objects. A class can contain properties and…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo