"Testing1"
Kotlin OOP
What is Kotlin OOP?
Kotlin's Object-Oriented Programming is a method of designing code using objects — self-contained units containing data (properties) and behavior (functions).
Key OOP Pillars in Kotlin
1. Class – A template to build objects
class Dog {
var breed = "Labrador"
fun bark() {
println("Woof!")
}
}
2. Object – A real-world instance of a class
val pet = Dog() Pet.bark() // Outputs: Woof!
3. Encapsulation – Wraps data + behavior together and hides details
class BankAccount {
private var balance = 1000
fun getBalance() = balance
}
4. Inheritance – Share functionality using a parent-child link
open class Animal {
fun sleep() = println("Sleeping...")
}
Class Cat : Animal()
5. Polymorphism – Same action, different implementations
open class Shape {
open fun draw() = println("Drawing Shape")
}
class Circle : Shape() {
Override fun draw() = println("Drawing Circle")
}
6. Abstraction – Hides complexity, shows essentials only
abstract class Machine {
abstract fun start()
}
class Laptop : Machine() {
override fun start() = println("Laptop booting...")
}
Why Use OOP in Kotlin?
- Builds modular code
- Encourages reuse
- Makes maintenance simpler
- Better organization of logic
Prefer Learning by Watching?
Watch these YouTube tutorials to understand KOTLIN Tutorial visually:
What You'll Learn:
- 📌 Kotlin Object Oriented Programming - Introduction
- 📌 Introduction to OOP in Kotlin