Structure of a class

Just like Java, classes in Kotlin are declared using the class keyword. The basic structure of a class consists of:

  • The class keyword
  • The name of the class
  • The header
  • The body of the class enclosed in curly braces

The header can consist of a primary constructor, a parent class if applicable, and an interface to implement if applicable.

Of all four parts, only the first two are compulsory. If the class has no body, you can skip the curly braces.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset