to a class member: When applied to a top-level declaration: Example: // Class is visible only to current module internal open class TalkativeButton{ // method is only visible to current class private fun yell() = println("Hey!") // method is visible to current class and derived classes protected fun whisper() = println("Let's talk!") } internal class MyTalkativeButton: TalkativeButton() { fun utter() = super.whisper() } MyTalkativeButton().utter() Primary constructor vs. secondary constructors Kotlin supports the specification of a "primary constructor" as part of the class definition itself, consisting of an argument list following the class name. This argument list supports an expanded syntax on Kotlin's standard function argument lists, that enables declaration of class properties in the primary constructor, including visibility, extensibility and mutability attributes. Additionally, when defining a subclass, properties in super-interfaces and super-classes can be overridden in the primary constructor. // Example of class using primary constructor syntax // (Only one constructor required for this class) open class BaseUser(open var isSubscribed: Boolean) open class PowerUser(protected val nickname: String, final override var isSubscribed: Boolean = true):BaseUser(isSubscribed) { } However, in cases where more than one constructor is needed for a class, a more general constructor can be used called secondary constructor syntax which closely resembles the constructor syntax used in most object-oriented languages like C++, C#, and Java. // Example of class using secondary constructor syntax // (more than one constructor required for this class) class Context class AttributeSet open class View(ctx:Context) { constructor(ctx: Context, attr: AttributeSet): this(ctx) } class MyButton : View { // Constructor #1 constructor(ctx: Context) : super(ctx) { } // Constructor #2 constructor(ctx: Context, attr: AttributeSet) : super(ctx, attr) { // ... } } Sealed classes The Sealed classes and interfaces restrict the subclass hierarchies, meaning more control over the inheritance hierarchy. Declaration of sealed interface and class: sealed interface Expr sealed class Job All the subclasses of the sealed class are defined at compile time. No new subclasses can be added to it after the compilation of the module having the sealed class. For example, a sealed class in a compiled jar file cannot be subclassed. sealed class Vehicle data class Car(val brandName: String, val owner: String, val color: String): Vehicle() class Bike(val brandName: String, val owner: String, val color: String): Vehicle() class Tractor(val brandName: String, val owner: String, val color: String): Vehicle() val kiaCar = Car("KIA", "John", "Blue") val hyundaiCar = Car("Hyundai", "Britto", "Green") Data classes