Kotlin Interview Questions Hindi mein

Kotlin कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Kotlin Foundations

1. Which statement about Kotlin is accurate?

  1. It is dynamically typed
  2. It only runs on Android
  3. It interoperates with Java and can use existing Java libraries
  4. It requires every function to live inside a class
जवाब देखें

जवाब: It interoperates with Java and can use existing Java libraries

Kotlin targets the JVM, Android, JS/Wasm and native, and calls Java directly.

पाठ: What Kotlin Is

2. What is `build.gradle.kts`?

  1. A Gradle build script written in the Kotlin DSL
  2. A compiled Kotlin library
  3. An Android manifest
  4. A ktlint configuration file
जवाब देखें

जवाब: A Gradle build script written in the Kotlin DSL

The .kts extension means a Kotlin script.

पाठ: Setting Up a Kotlin Project

3. What is the difference between `val` and `var`?

  1. `val` objects are always deeply immutable
  2. `val` is only for numbers
  3. `var` makes a value nullable
  4. `val` cannot be reassigned after initialisation; `var` can
जवाब देखें

जवाब: `val` cannot be reassigned after initialisation; `var` can

Prefer val and use var only when reassignment is needed.

पाठ: Variables, Functions and Strings

Null Safety and the Type System

4. What does `user?.email ?: "none"` evaluate to when `user` is null?

  1. null
  2. "none"
  3. It throws NullPointerException
  4. An empty string
जवाब देखें

जवाब: "none"

The safe call yields null and elvis supplies the fallback.

पाठ: Nullable Types and Safe Operators

5. Which range excludes its end value?

  1. `0..5`
  2. `0..<5` (or `0 until 5`)
  3. `5 downTo 0`
  4. `0..5 step 1`
जवाब देखें

जवाब: `0..<5` (or `0 until 5`)

`..` is inclusive; `..<` and `until` exclude the end.

पाठ: when Expressions and Ranges

6. What does `value as? String` return if `value` is an Int?

  1. An empty string
  2. It throws ClassCastException
  3. The Int converted to text
  4. null
जवाब देखें

जवाब: null

as? is the safe cast.

पाठ: Type Checks, Casts and the Type Hierarchy

Classes and Data Modelling

7. What does `class Point(val x: Int, val y: Int)` declare?

  1. A class with a primary constructor and two read-only properties
  2. A function named Point
  3. A data class with copy()
  4. An open class that can be subclassed
जवाब देखें

जवाब: A class with a primary constructor and two read-only properties

val in the constructor creates properties; classes are final by default.

पाठ: Classes, Constructors and Properties

8. Which function is NOT generated for a data class?

  1. `equals()`
  2. `copy()`
  3. `save()`
  4. `component1()`
जवाब देखें

जवाब: `save()`

Data classes generate equals, hashCode, toString, copy and componentN.

पाठ: Data Classes

9. Why can `when` over a sealed interface omit `else`?

  1. when never needs else
  2. Sealed types cannot be used in when
  3. The compiler knows all direct subtypes, so it can check exhaustiveness
  4. Sealed types are always enums
जवाब देखें

जवाब: The compiler knows all direct subtypes, so it can check exhaustiveness

Sealed hierarchies are closed.

पाठ: Sealed Types and Enums

Functional Kotlin

10. What does `it` refer to in `list.map { it * 2 }`?

  1. The single parameter of the lambda, each element in turn
  2. The list itself
  3. The index of the element
  4. The result of the previous call
जवाब देखें

जवाब: The single parameter of the lambda, each element in turn

it is the implicit name of a single lambda parameter.

पाठ: Lambdas and Higher-Order Functions

11. What is the key difference between a List chain and a Sequence chain?

  1. Sequences are mutable lists
  2. Sequences are always faster
  3. Lists cannot be filtered
  4. Sequences are evaluated lazily, element by element
जवाब देखें

जवाब: Sequences are evaluated lazily, element by element

Lazy evaluation avoids intermediate collections and allows early termination.

पाठ: Collections and Sequences

12. Which scope function returns the object itself and exposes it as `this`?

  1. `let`
  2. `apply`
  3. `run`
  4. `with`
जवाब देखें

जवाब: `apply`

apply is for configuring an object; also returns it too but uses it.

पाठ: Extension Functions and Scope Functions

Object-Oriented Kotlin

13. What does the `internal` modifier mean?

  1. Visible only inside the class
  2. Visible everywhere within the same module
  3. Visible only to subclasses
  4. Visible only within the same file
जवाब देखें

जवाब: Visible everywhere within the same module

internal is module-wide visibility.

पाठ: Interfaces, Inheritance and Visibility

14. What does an `object` declaration create?

  1. A new instance on every access
  2. A data class
  3. An abstract class
  4. A singleton: a class with exactly one lazily created instance
जवाब देखें

जवाब: A singleton: a class with exactly one lazily created instance

object declarations are Kotlin singletons.

पाठ: Object Declarations and Companion Objects

15. What does `val x by lazy { compute() }` do?

  1. Calls compute() on first access and caches the result
  2. Calls compute() on every access
  3. Calls compute() in a background thread at startup
  4. Makes x nullable
जवाब देखें

जवाब: Calls compute() on first access and caches the result

lazy initialises once and reuses the value.

पाठ: Delegation: by lazy and Class Delegation

Coroutines and Flow

16. Which builder returns a Deferred whose result you await?

  1. `runBlocking`
  2. `launch`
  3. `async`
  4. `delay`
जवाब देखें

जवाब: `async`

launch returns a Job; async returns `Deferred<T>`.

पाठ: Suspend Functions and Coroutine Builders

17. What happens to child coroutines when their scope is cancelled?

  1. They are restarted
  2. They keep running in GlobalScope
  3. They are cancelled too
  4. Nothing; children are independent of scopes
जवाब देखें

जवाब: They are cancelled too

Structured concurrency ties child lifetimes to the parent.

पाठ: Structured Concurrency and Cancellation

18. Which dispatcher suits blocking file or JDBC calls?

  1. `Dispatchers.IO`
  2. `Dispatchers.Main`
  3. `Dispatchers.Unconfined`
  4. No dispatcher; call them directly on the main thread
जवाब देखें

जवाब: `Dispatchers.IO`

IO is sized for blocking operations; Default is for CPU work.

पाठ: Dispatchers and Flow

Practical Kotlin

19. What does `check(condition)` throw when the condition is false?

  1. Nothing; it only logs
  2. `IllegalArgumentException`
  3. `NullPointerException`
  4. `IllegalStateException`
जवाब देखें

जवाब: `IllegalStateException`

require is for arguments, check is for state.

पाठ: Error Handling: Exceptions and Result

20. Why is a `reified` type parameter useful?

  1. It makes a type parameter nullable
  2. It lets an inline function check or access the actual type at runtime
  3. It disables type erasure for all classes
  4. It makes the function run faster on all platforms
जवाब देखें

जवाब: It lets an inline function check or access the actual type at runtime

Only inline functions can have reified type parameters.

पाठ: Generics and Variance

21. What does `@JvmStatic` on a companion object function do?

  1. Makes it run on a background thread
  2. Makes it callable from Java as a static method on the class
  3. Prevents Java from calling it
  4. Marks it as thread-safe
जवाब देखें

जवाब: Makes it callable from Java as a static method on the class

Without it, Java must call it via the Companion instance.

पाठ: Java Interoperability

Ecosystem and Production

22. What is Jetpack Compose?

  1. A build tool replacing Gradle
  2. A server framework from JetBrains
  3. A Kotlin linter
  4. Android's declarative UI toolkit built on @Composable functions
जवाब देखें

जवाब: Android's declarative UI toolkit built on @Composable functions

Compose describes UI as a function of state.

पाठ: Kotlin on the Server and Android

23. How does common KMP code access a platform-specific API?

  1. It declares an `expect` declaration with `actual` implementations per platform
  2. It uses reflection at runtime
  3. It cannot; common code is pure math only
  4. It calls Java directly on every platform
जवाब देखें

जवाब: It declares an `expect` declaration with `actual` implementations per platform

expect/actual connects common code to platform code.

पाठ: Kotlin Multiplatform

24. What does `runTest` from kotlinx-coroutines-test provide?

  1. A mocking DSL for suspend functions
  2. A linter for coroutine code
  3. A test coroutine scope with virtual time, so delays are skipped
  4. A way to run tests on Android devices only
जवाब देखें

जवाब: A test coroutine scope with virtual time, so delays are skipped

Virtual time makes coroutine tests fast and deterministic.

पाठ: Testing and Idiomatic Style

25. Which practice belongs on a Kotlin production checklist?

  1. Add else to every when over a sealed type
  2. Use !! wherever the compiler complains
  3. Launch coroutines in lifecycle-bound scopes instead of GlobalScope
  4. Call runBlocking inside suspend functions
जवाब देखें

जवाब: Launch coroutines in lifecycle-bound scopes instead of GlobalScope

Structured scopes prevent leaked work.

पाठ: A Kotlin Production Checklist

← कोर्स पर वापस जाएँ