Non-nullable types by default
📖 Scenario: You are creating a simple Kotlin program to store and display a person's name and age. Kotlin treats types as non-nullable by default, which means variables cannot hold null unless explicitly allowed.
🎯 Goal: Build a Kotlin program that defines a non-nullable name variable and a non-nullable age variable, then prints them.
📋 What You'll Learn
Create a non-nullable
name variable of type String with the value "Alice".Create a non-nullable
age variable of type Int with the value 30.Print the
name and age variables in the format: Name: Alice, Age: 30.💡 Why This Matters
🌍 Real World
Non-nullable types help prevent errors by ensuring variables always have valid values, which is important in apps that handle user data.
💼 Career
Understanding Kotlin's type system is essential for Android developers and anyone working with Kotlin to write safe and reliable code.
Progress0 / 4 steps