Any2Quiz
Quizzes / Computer Science / Languages / Kotlin

Syntax Quiz - Languages Kotlin

Free practice quiz: Syntax (Languages Kotlin). 51 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

This Languages Kotlin practice quiz has 51 multiple-choice questions on Syntax, and 51 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.

Start quiz: 51 questions, free

Sample questions

  1. In Kotlin, what keyword is used to declare a variable that cannot be reassigned after its initial assignment?

    Show answer

    Answer: B. val

    In Kotlin, `val` is used to declare read-only variables (immutable), meaning they cannot be reassigned after their initial assignment. `var` is used for mutable variables.

  2. What is the correct syntax for a multi-line comment in Kotlin?

    Show answer

    Answer: B. /* comment another comment */

    Multi-line comments in Kotlin are enclosed within `/*` and `*/`.

  3. What does the `val` keyword signify in Kotlin?

    Show answer

    Answer: B. A read-only (immutable) variable

    `val` declares a read-only property in Kotlin, which means it can be assigned a value only once.

  4. How do you declare a default parameter value for a function in Kotlin?

    Show answer

    Answer: A. fun greet(name: String = "Guest")

    Default parameter values are assigned using the `=` operator in the function signature.

  5. Which of the following is the Kotlin syntax for a `for` loop iterating over a range of numbers from 1 to 5 (inclusive)?

    Show answer

    Answer: A. for (i in 1..5) { ... }

    Kotlin's `for` loop uses the `in` keyword and the range operator `..` for iterating over sequences, including number ranges.

Take the full quiz

More questions in this quiz

Answers and explanations are in the full quiz.

  1. Which of the following is the correct way to declare a nullable String in Kotlin?
  2. What is the primary difference between `==` and `===` operators in Kotlin?
  3. Which keyword is used to define a function in Kotlin?
  4. What is the correct syntax for a single-line comment in Kotlin?
  5. Which of the following represents an immutable list in Kotlin?
  6. How do you create an instance of a class named `MyClass` in Kotlin?
  7. Which statement correctly defines an extension function for the `String` class in Kotlin?
  8. What is the purpose of the `when` expression in Kotlin?
  9. Which of the following is NOT a valid way to handle nullability in Kotlin?
  10. Which keyword is used to create a data class in Kotlin, which automatically generates `equals()`, `hashCode()`, `toString()`, etc.?
  11. What does the `lateinit` keyword do in Kotlin?
  12. Which of the following is the correct way to access an element at index 2 in a Kotlin `List` named `myList`?
  13. What is the purpose of the `object` keyword in Kotlin?
  14. Which of the following is the Kotlin equivalent of Java's `final` keyword?
  15. What is the scope resolution operator in Kotlin?
  16. How do you declare a variable that can be reassigned in Kotlin?
  17. What is the correct syntax for creating a `HashMap` in Kotlin?
  18. Which keyword is used to define a constructor for a class in Kotlin?
  19. Which of the following is a correct way to declare a function that returns an `Int` in Kotlin?
  20. What is the role of the `as?` operator in Kotlin?
  21. What is the Kotlin keyword for an immutable property that can be a compile-time constant?
  22. Which of the following correctly defines a nullable `Int` variable initialized to null?
  23. What is the purpose of the `object` keyword when used with `companion`?
  24. Which of the following is a valid way to declare an empty `ArrayList` in Kotlin?
  25. What is the Kotlin equivalent of Java's `instanceof` operator?
  26. Which of these expressions is used for safe iteration over a nullable collection in Kotlin?
  27. What is the primary purpose of the `require` function in Kotlin?
  28. What does the `return@` syntax in Kotlin achieve?
  29. Which keyword is used to define a read-only property that is initialized at runtime?
  30. What is the Kotlin syntax for string templating or interpolation?
  31. Which of the following operators is used to invoke a lambda expression or a function reference?
  32. What is the purpose of the `by` keyword in Kotlin delegation?
  33. How do you declare a nullable `Boolean` in Kotlin?
  34. What is the Kotlin syntax for a `while` loop?
  35. Which operator is used for safe property access on a nullable object in Kotlin?
  36. What does the `inline` keyword imply for a function in Kotlin?
  37. What is the correct syntax for a sealed class in Kotlin?
  38. Which symbol denotes a lambda expression in Kotlin?
  39. What is the purpose of the `infix` modifier for a function in Kotlin?
  40. Which of the following is NOT a primitive type in Kotlin?
  41. What is the correct way to declare a top-level property in Kotlin?
  42. Which keyword is used to override a member from a superclass or interface in Kotlin?
  43. What is the purpose of the `vararg` keyword in Kotlin function parameters?
  44. Which of the following is the Kotlin syntax for a `do-while` loop?
  45. What is the `?.let { ... }` construct in Kotlin used for?
  46. Which keyword is used to define a singleton object in Kotlin?

More quizzes

Browse all Kotlin quizzes

More to play

Daily ChallengeA new quiz every day. Keep your streak.HangmanGuess the word, letter by letter.Story QuestLearn through short interactive stories.All quizzesCBSE, ICSE, competitive exams and more.