Kotlin OOP

Object-Oriented Programming (OOP) in Kotlin is based on objects and classes. Kotlin fully supports OOP principles and adds modern features that make code cleaner, safer, and more concise than Java.
1. Core OOP Concepts in Kotlin
It follows 4 main OOP principles:
Class & Object
Encapsulation
Inheritance
Polymorphism
2. Class & Object
Creating a Class
Creating an Object
3. Constructors
Primary Constructor
Usage:
Secondary Constructor
4. Encapsulation
Encapsulation means hiding internal data and exposing only what is necessary.
Access modifiers:
public(default)privateprotectedinternal
5. Inheritance
open Keyword
Classes are final by default in Kotlin.
Child Class
6. Polymorphism
Same function name, different behavior.
7. Abstract Classes
8. Interfaces
9. Data Classes
Used to hold data only.
Automatically provides:
toString()equals()hashCode()copy()
10. Object Keyword (Singleton)
11. Companion Object (Static)
12. Sealed Classes
Used for restricted class hierarchies.
Summary
It fully supports OOP
Classes are final by default
Less boilerplate than Java
Powerful features like data, sealed, object
