class KotlinClassName { // Properties or data members ... // Functions or Methods ... }
In Kotlin abstract class is declared by declaring abstract key word with class declaration. Such classes cannot be instantiated. They are open by default and can be sub-classed by other non-abstract classes. Abstract methods and fields of these classes are declared with abstract key word. Any non-abstract members of an abstract class are final by default.
private: Any functions, properties etc are not accessible outside the Kotlin file, where it is defined.
public: All functions and properties defind inside class can be accessed anywhere. Default Kotlin classes are public.
protected: Sub classes can access class/interface elements (includes member properties and functions unless they are marked private).
internal: All elements defined are accessible within the same module.
All the classes in Kotlin are final (non-inheritable). To allow a class to be inherited, it is marked with the open modifier. The child class carries all the methods and properties of parent class, and can also have its own. The extened classes work similarly, as in Java. However, unlike Java, in Kotlin, It is also possible to extend a class, without use of inheritance, by use of extension functions.
In polymorphism, same method defined by parent class behaves differently based on the object. Kotlin supports compile time and runtime polymorphism. In compile-time polymorphism or overloading, the function name remain same but signatures (parameters) and/or return type is different. For run-time polymorphism, or overriding the call to methods is resolved at runtime by JVM (not by compiler).
In addition to Object Oriented features, Kotlin also support functional programming. Lambdas (anonymous functions treated as values), higher order function (taking function as paramater or return function) are used to do functional programming with Kotlin.