Classes and Functions in Kotlin

Classes in Kotlin:

Classes in Kotlin follow a really simple structure. However, there are some slight differences from Java that you will want to know before we continue. You could also use the REPL that comes bundled with the Kotlin plugin. You will find it in Tools -> Kotlin -> Kotlin REPL

How to declare a class in Kotlin?

If you want to declare a class, you just need to use the keyword class:

class MainActivity {

 }

Classes have a unique default constructor. We’ll see that we can create extra constructors for some exceptional cases, but keep in mind that most situations only require a single constructor. Parameters are written just after the name. Brackets are not required if the class doesn’t have any content:

class Person(name: String, surname: String)

Where’s the body of the constructor then? You can declare an init block: