u/Android_Alchemy

▲ 1 r/Kotlin

Here's the rewrite — same content, same code, but written like an actual developer who made a YouTube video and is sharing it casually:

Hey everyone! Just dropped a full video on Kotlin Constructors — here's a quick summary if you're short on time.

1. Primary Constructor

In Kotlin, the constructor goes right in the class header. No separate block, no boilerplate.

kotlin

class User(var name: String, var age: Int)

fun main() {
    val alice = User("Sid", 21)
    println(alice.name) // Sid
    println(alice.age)  // 21
}

That's it. Declare and move on.

2. Init Block

Need to run some logic the moment an object is created? Use init. It fires automatically — you don't call it yourself.

kotlin

class User(var num1: Int, var num2: Int) {
    val result = num1 * num2
    init {
        println(result) // runs on creation
    }
}

fun main() {
    val num = User(34, 67) // prints 2278
}

3. Secondary Constructors

Sometimes you need more than one way to build an object. Secondary constructors handle that — but they have to delegate to the primary using this(...).

kotlin

class Man(var name: String, var age: Int) {
    constructor(name: String) : this(name, 18)  // default age = 18
    constructor() : this("Sid", 12)             // everything defaulted
}

fun main() {
    val user1 = Man("Sasuke", 2)
    val user2 = Man()
    println(user1.name) // Sasuke
    println(user2.name) // Sid
}

4. Companion Object

Companion objects belong to the class, not to any instance — Kotlin's answer to static methods.

kotlin

class Calculator(val num1: Int, val num2: Int) {
    init {
        println("Sum: ${num1 + num2}")
        println("Product: ${num1 * num2}")
        println("Division: ${num1 / num2}")
    }
    companion object {
        fun add(a: Int, b: Int) = a + b
        fun multiply(a: Int, b: Int) = a * b
        fun divide(a: Int, b: Int) = a / b
    }
}

// No object needed:
Calculator.add(45, 9) // 54

Full video with live coding and a challenge is on my channel. Drop questions in the comments if anything's unclear!

u/Android_Alchemy — 12 days ago

​

Just uploaded my first Kotlin tutorial where I cover:

- Variables

- Data types

- Control flow

- Loops

- Beginner-friendly explanations

- Small practice project at the end

I’m documenting my journey from beginner to professional Android developer, so if you're learning Kotlin, Android, or coding in general, this channel will focus on practical and structured learning instead of random theory dumps.

Would genuinely appreciate feedback from developers here:

- Is the pacing good?

- What topics should I cover next?

- What do beginners struggle with most in Kotlin?

Channel/video link: https://youtu.be/q0I7Sg9RuZs?si=irk8K3e-HVBYg5pW

Goal is to make clean, straight-to-the-point content that actually helps people build apps instead of just watching tutorials endlessly.

u/Android_Alchemy — 13 days ago