Top 100 Kotlin Interview Question & Answer | CodeBaaj |


πŸ”Ή Kotlin Basics (1–20)

1. What is Kotlin?
Kotlin is a modern, statically typed programming language developed by JetBrains, mainly used for Android development.

2. Is Kotlin compiled or interpreted?
Kotlin is a compiled language.

3. Kotlin runs on which platform?
JVM, Android, JavaScript, and Native.

4. Is Kotlin interoperable with Java?
Yes, Kotlin is 100% interoperable with Java.

5. Who developed Kotlin?
JetBrains.

6. What file extension is used in Kotlin?
.kt

7. Is Kotlin open source?
Yes.

8. Kotlin is statically typed or dynamically typed?
Statically typed.

9. What is val in Kotlin?
Immutable variable (cannot be changed).

10. What is var in Kotlin?
Mutable variable (can be changed).

11. How to print output in Kotlin?
println("Hello")

12. What is the entry point of Kotlin program?
fun main() {}

13. Is semicolon mandatory in Kotlin?
No.

14. What is type inference?
Compiler automatically detects variable type.

15. Can we use Kotlin for backend development?
Yes (Spring Boot, Ktor).

16. What is JVM?
Java Virtual Machine.

17. Kotlin supports functional programming?
Yes.

18. What is a package in Kotlin?
Used to group related classes and functions.

19. Default visibility modifier in Kotlin?
public

20. Kotlin supports OOP?
Yes.


πŸ”Ή Data Types & Variables (21–35)

21. Common data types in Kotlin?
Int, Double, Float, Long, Boolean, Char, String.

22. Difference between Int and Long?
Int = 32-bit, Long = 64-bit.

23. What is String template?
"My name is $name"

24. Is Kotlin null-safe?
Yes.

25. What is nullable type?
Type that can hold null (String?).

26. What is !! operator?
Forces null value (can cause exception).

27. What is safe call operator?
?.

28. What is Elvis operator?
?:

29. Difference between == and ===?
== checks value, === checks reference.

30. Can Kotlin variable be null by default?
No.

31. What is Any type?
Root class of all classes.

32. What is Unit?
Equivalent to void.

33. What is Nothing type?
Represents no value.

34. Type casting operator?
as

35. Smart casting means?
Automatic casting by compiler.


πŸ”Ή Control Flow (36–50)

36. What is when in Kotlin?
Replacement for switch.

37. Kotlin if is expression or statement?
Expression.

38. Loop types in Kotlin?
for, while, do-while.

39. How to use range in Kotlin?
1..10

40. What is downTo?
Loop in reverse order.

41. What is step?
Defines increment/decrement.

42. What is break?
Stops loop.

43. What is continue?
Skips iteration.

44. Can when return value?
Yes.

45. What is label in Kotlin?
Used to control flow.

46. Infinite loop in Kotlin?
while(true)

47. Can if-else be nested?
Yes.

48. Can when be used as expression?
Yes.

49. Default branch in when?
else

50. Kotlin supports ternary operator?
No (if expression used instead).


πŸ”Ή Functions & Lambda (51–65)

51. What is function in Kotlin?
Block of reusable code.

52. Function keyword?
fun

53. Default parameter?
Yes.

54. Named arguments?
Yes.

55. What is lambda?
Anonymous function.

56. Lambda syntax?
{ a, b -> a + b }

57. Higher-order function?
Function that takes function as parameter.

58. Inline function?
Improves performance.

59. What is it keyword?
Implicit parameter in lambda.

60. Single expression function?
fun add(a:Int,b:Int)=a+b

61. What is recursion?
Function calling itself.

62. Tail recursion?
Optimized recursion.

63. Extension function?
Adds function to class.

64. Anonymous function?
Function without name.

65. Function return type?
Declared using :


πŸ”Ή OOP in Kotlin (66–85)

66. Class keyword?
class

67. Primary constructor?
Constructor in class header.

68. Secondary constructor?
Defined using constructor.

69. Inheritance keyword?
:

70. Default class in Kotlin?
Final.

71. Open keyword?
Allows inheritance.

72. Interface keyword?
interface

73. Abstract class keyword?
abstract

74. Can interface have implementation?
Yes.

75. Multiple inheritance supported?
Yes (via interfaces).

76. Data class?
Used to hold data.

77. Data class keyword?
data

78. What is sealed class?
Restricted class hierarchy.

79. Enum class?
Defines constants.

80. Object keyword?
Creates singleton.

81. Companion object?
Static members.

82. Visibility modifiers?
public, private, protected, internal.

83. Constructor visibility control?
Yes.

84. Overriding keyword?
override

85. Can Kotlin override Java methods?
Yes.


πŸ”Ή Collections, Coroutines & Misc (86–100)

86. Immutable list?
listOf()

87. Mutable list?
mutableListOf()

88. Map type?
key-value pairs.

89. Set νŠΉμ§•?
No duplicates.

90. What is Coroutine?
Lightweight thread.

91. Coroutine scope?
Defines lifecycle.

92. suspend keyword?
Pauses execution.

93. Launch vs async?
launch β†’ no result, async β†’ returns result.

94. What is Flow?
Asynchronous data stream.

95. Exception handling keyword?
try-catch-finally.

96. Kotlin supports checked exceptions?
No.

97. Lateinit keyword?
Late initialization.

98. Lazy keyword?
Initialize when needed.

99. Kotlin vs Java main advantage?
Null safety, concise code.

100. Is Kotlin official Android language?
Yes.


Leave a Reply

Your email address will not be published. Required fields are marked *