class KotlinClassName { // Properties or data members ... // Functions or Methods ... }
In Kotlin abstract class is declared by declaring abstract key word in front of the class. Such classes cannot be instantiated. It is open by default and can be sub-classed by other non-abstract classes. Abstract methods and fields of abstract class 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 by others, it is marked with the open modifier.
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, the function signatures remains the same but parameters or return type is different. At compile time, function called is resolved based on the type of parameters. For run-time polymorphism, the compiler resolves a call to overridden/overloaded methods at runtime.