MCQ Related “Kotlin”

  1. What is the primary purpose of Kotlin?
    • A) Web Development
    • B) Mobile Development
    • C) Data Science
    • D) System Programming
  2. Which company developed Kotlin?
    • A) Microsoft
    • B) JetBrains
    • C) Google
    • D) Oracle
  3. Kotlin is fully interoperable with which language?
    • A) Swift
    • B) Java
    • C) C#
    • D) Python
  4. What keyword is used to declare a variable in Kotlin?
    • A) var
    • B) let
    • C) def
    • D) set
  5. What is the extension of Kotlin source files?
    • A) .k
    • B) .kt
    • C) .kotlin
    • D) .kts
  6. Which of the following is a valid way to declare a constant in Kotlin?
    • A) const val
    • B) val const
    • C) final val
    • D) val constant
  7. How do you define a function in Kotlin?
    • A) function myFunction() {}
    • B) fun myFunction() {}
    • C) def myFunction() {}
    • D) myFunction() {}
  8. Which of the following keywords is used to define a class in Kotlin?
    • A) class
    • B) define
    • C) object
    • D) module
  9. What symbol is used for comments in Kotlin?
    • A) //
    • B) /*
    • C) #
    • D) —
  10. What type is used to represent a nullable variable in Kotlin?
    • A) ?
    • B) null
    • C) undefined
    • D) None
  11. How do you create an immutable list in Kotlin?
    • A) listOf()
    • B) mutableListOf()
    • C) arrayOf()
    • D) ArrayList()
  12. Which collection class allows duplicates in Kotlin?
    • A) Set
    • B) List
    • C) Map
    • D) Hashtable
  13. What is the correct syntax for a for loop in Kotlin?
    • A) for (i in 1..10) {}
    • B) for i in 1 to 10 {}
    • C) loop (i: 1 to 10) {}
    • D) for i = 1 to 10 {}
  14. How do you handle exceptions in Kotlin?
    • A) try-catch
    • B) catch-throw
    • C) exception-handle
    • D) throw-try
  15. Which keyword is used for inheritance in Kotlin?
    • A) extends
    • B) inherits
    • C) :
    • D) from
  16. What is the default visibility modifier for classes in Kotlin?
    • A) public
    • B) private
    • C) internal
    • D) protected
  17. Which of the following is used for testing in Kotlin?
    • A) JUnit
    • B) NUnit
    • C) TestNG
    • D) Mocha
  18. What keyword is used to define a data class in Kotlin?
    • A) data
    • B) class
    • C) object
    • D) model
  19. How do you define an interface in Kotlin?
    • A) interface MyInterface {}
    • B) MyInterface interface {}
    • C) class MyInterface {}
    • D) object MyInterface {}
  20. What type of loop executes at least once in Kotlin?
    • A) for loop
    • B) while loop
    • C) do-while loop
    • D) infinite loop
  21. How do you declare a property in a Kotlin class?
    • A) var name: String
    • B) property name: String
    • C) let name: String
    • D) field name: String
  22. Which function is used to read user input in Kotlin?
    • A) input()
    • B) readLine()
    • C) readInput()
    • D) scan()
  23. How would you declare a generic type in Kotlin?
    • A) <T>
    • B) <E>
    • C) <R>
    • D) <K>
  24. What is the purpose of the companion object in Kotlin?
    • A) Static members
    • B) Instance variables
    • C) Functions only
    • D) Inheritance
  25. Which file extension is used for Kotlin scripts?
    • A) .ks
    • B) .kts
    • C) .kat
    • D) .kotlin
  26. How do you define a lambda expression in Kotlin?
    • A) { x -> x + 2 }
    • B) (x) => x + 2
    • C) lambda x: x + 2
    • D) (x) { return x + 2 }
  27. Which function can be used to concatenate strings in Kotlin?
    • A) concat()
    • B) append()
    • C) + operator
    • D) join()
  28. What does the ! operator do in Kotlin?
    • A) Not operator
    • B) Mandatory operator
    • C) Nullable operator
    • D) Private modifier
  29. How do you access a property in a class in Kotlin?
    • A) className.propertyName
    • B) propertyName.className
    • C) instanceName.propertyName
    • D) propertyName(instanceName)
  30. In Kotlin, what is the use of lateinit?
    • A) Initialize later
    • B) Late object creation
    • C) Delay function execution
    • D) Asynchronous execution
  31. How do you create a single instance class in Kotlin?
    • A) class Singleton {}
    • B) object Singleton {}
    • C) single class Singleton {}
    • D) instance Singleton {}
  32. What is the result of the expression 5 == 5 in Kotlin?
    • A) 0
    • B) true
    • C) null
    • D) false
  33. Which keyword is used to define an abstract class in Kotlin?
    • A) abstract
    • B) class
    • C) virtual
    • D) interface
  34. What does the apply function do in Kotlin?
    • A) Applies a transformation
    • B) Executes a block of code on an object
    • C) Returns a new object
    • D) Sets a new value
  35. How do you define a list in Kotlin that is mutable?
    • A) mutableListOf()
    • B) ArrayList()
    • C) arrayOf()
    • D) List()
  36. What does the with function do in Kotlin?
    • A) Executes a block of code within a context
    • B) Merges two objects
    • C) Transfers data
    • D) Clones an object
  37. Which of the following built-in functions allows filtering a list?
    • A) filter()
    • B) select()
    • C) choose()
    • D) find()
  38. How do you define an enum class in Kotlin?
    • A) enum EnumClass {}
    • B) class EnumClass {}
    • C) enum class EnumClass {}
    • D) class enum EnumClass {}
  39. What is the purpose of the in keyword in Kotlin?
    • A) Define range
    • B) Define extend
    • C) Specify nullability
    • D) A member keyword
  40. Which method can be used to sort a list in Kotlin?
    • A) orderBy()
    • B) sort()
    • C) sorted()
    • D) arrange()
  41. How do you define a secondary constructor in a Kotlin class?
    • A) constructor(param: Type) {}
    • B) className(param: Type) {}
    • C) init(param: Type) {}
    • D) secondary constructor(param: Type) {}
  42. What is the purpose of the sealed class in Kotlin?
    • A) Define single inheritance
    • B) Restrict class hierarchies
    • C) Create singleton classes
    • D) Allow inheritance
  43. How do you declare a functional type in Kotlin?
    • A) (Type) -> Type
    • B) Type -> Type
    • C) fun Type: Type
    • D) function Type -> Type
  44. What operator is used to call a super class method in Kotlin?
    • A) %
    • B) super
    • C) &
    • D) call
  45. How do you format a string in Kotlin?
    • A) String.format()
    • B) formatString()
    • C) “$value”
    • D) String.interpolate()
  46. Which feature was introduced in Kotlin 1.3?
    • A) Coroutines
    • B) Type inference
    • C) Lambda expressions
    • D) Data classes
  47. What is the purpose of the modifier in Kotlin functions?
    • A) Change access
    • B) Change scope
    • C) Use inline
    • D) Mark description
  48. Which operator is used for safe calls in Kotlin?
    • A) ?
    • B) !!
    • C) ?
    • D) @
  49. What is the purpose of the when expression in Kotlin?
    • A) Loop iteration
    • B) Conditional statements
    • C) Data transformation
    • D) Event handling
  50. How do you start Kotlin’s REPL (Read-Eval-Print Loop)?
    • A) Kotlin REPL
    • B) Run Kotlin
    • C) kotlinc
    • D) kotlin