Recall & Review
beginner
What is explicit type declaration in Kotlin?
Explicit type declaration means specifying the type of a variable or function explicitly in the code, like
val name: String = "John".Click to reveal answer
beginner
Why use explicit type declaration in Kotlin?
It helps make code clearer, easier to read, and can prevent errors by telling the compiler exactly what type a variable should hold.
Click to reveal answer
beginner
How do you declare an integer variable with explicit type in Kotlin?
You write:
val number: Int = 10. Here, Int is the explicit type.Click to reveal answer
beginner
Can you declare a variable without explicit type in Kotlin?
Yes, Kotlin can infer the type automatically, for example:
val name = "Alice". But explicit type is useful for clarity or complex cases.Click to reveal answer
intermediate
Show an example of explicit type declaration for a function return type in Kotlin.
Example:
fun greet(): String { return "Hello" }. The : String declares the function returns a String explicitly.Click to reveal answer
What does explicit type declaration do in Kotlin?
✗ Incorrect
Explicit type declaration means you tell Kotlin exactly what type a variable or function has.
Which of these is an example of explicit type declaration?
✗ Incorrect
Option A shows explicit type
Int declared for variable age.What is the explicit return type in this function?
fun add(a: Int, b: Int): Int { return a + b }✗ Incorrect
The function explicitly declares it returns an
Int.If you omit explicit type declaration, Kotlin will:
✗ Incorrect
Kotlin can infer types automatically if you don't specify them.
Which keyword is used to declare a variable with explicit type in Kotlin?
✗ Incorrect
Both
var and val can be used with explicit type declarations.Explain what explicit type declaration is and why it is useful in Kotlin.
Think about how telling the type helps the compiler and other programmers.
You got /2 concepts.
Write a Kotlin variable declaration with explicit type and explain each part.
Remember the order: keyword, name, colon, type, equals, value.
You got /5 concepts.