A single-file Kotlin project showcasing all core OOP concepts abstraction, encapsulation, inheritance, and polymorphism along with data classes, enum classes, sealed classes, generics, companion objects, singletons, delegation, and extension functions, with runnable examples.
This repository is a one-file Kotlin project that demonstrates the core concepts of Object-Oriented Programming (OOP) using idiomatic Kotlin features.
The code is heavily commented and designed to be self-explanatory for learners.
- Abstraction β Interfaces & Abstract classes
- Encapsulation β Private/protected fields with controlled access
- Inheritance & Polymorphism β Open classes, overrides, and dynamic behavior
- Data Classes & Enum Classes β Idiomatic Kotlin modeling
- Sealed Classes β Exhaustive
whenusage - Generics & Delegation β Reusable repository pattern
- Singletons & Companion Objects β
objectkeyword and static-like members - Extension Functions β Cleaner functionality extension
- Error Handling β Safe validations with
requireand exceptions
-
Clone the repo:
git clone https://github.com/your-username/kotlin-oop-guide.git cd kotlin-oop-guide -
Compile and run with Kotlin (ensure you have the Kotlin compiler installed):
kotlinc Main.kt -include-runtime -d oop-demo.jar java -jar oop-demo.jar
-
Youβll see console output demonstrating each OOP concept in action.
.
βββ Main.kt # Single Kotlin file with OOP examples
βββ README.md # This documentation
=== ENUM ===
Role=MODERATOR, canApprove=true
=== INHERITANCE + POLYMORPHISM ===
Manager Asha is planning and reviewing (0 reports)
Intern Ravi is learning and assisting
...
This project is intended as a study reference for B.Tech / CS students or anyone learning Kotlin OOP.
Itβs a quick way to see all major OOP principles in one place.
This project is open-source .