Kotlin Professional Certification
Kotlin is a statically-typed programming language created by JetBrains, known for its modern, expressive, and concise syntax. It is fully interoperable with Java, meaning it can work seamlessly with existing Java code and libraries.
Kotlin is a modern, statically-typed programming language developed by JetBrains, designed to be fully interoperable with Java while offering concise syntax, enhanced safety features, and powerful tooling. It is widely used for Android development and server-side applications, and its versatility extends to web development with Kotlin/JS and native development with Kotlin/Native. Kotlin emphasizes readability and reduces boilerplate code, making it a popular choice for developers seeking a more efficient and expressive alternative to Java.
Here are the quiz questions and answers :
What keyword is used to define a class in Kotlin?
‘class’
‘classify’
‘type’
‘define’
2.Which of the following is used to declare a read-only variable in Kotlin?
‘var’
‘let’
‘val’
‘const’
3.How do you declare a nullable type in Kotlin?
‘String?’
‘String!!’
‘String@’
‘String$’
4.What is the primary constructor syntax in Kotlin?
‘class MyClass(val x: Int)’
‘class MyClass(x: Int) { … }’
‘class MyClass(x: Int) { constructor(x: Int) { … } }’
‘class MyClass { constructor(x: Int) { … } }’
5.How do you define a function that does not return any value in Kotlin?
‘fun myFunction(): Unit { … }’
‘fun myFunction() { … }’
‘fun myFunction() -> Void { … }’
‘function myFunction() { … }’
6.Which keyword is used to extend a class or interface in Kotlin?
‘extend’
‘implements’
‘inherits’
‘:’
7.What is the purpose of the ‘data’ keyword in Kotlin?
To define data classes that automatically generate ‘equals()’, ‘hashCode()’, and ‘toString()’ methods
To define classes with mutable properties
To create database connections
To declare variables used for data storage
8.How do you handle exceptions in Kotlin?
‘try-catch-finally’
‘try-catch’
‘handle-catch’
‘try-throw’
9.Which keyword is used to declare an interface in Kotlin?
‘interface’
‘abstract’
‘impl’
‘class’
10.How do you declare a top-level function in Kotlin?
‘fun myFunction() { … }’
‘top fun myFunction() { … }’
‘function myFunction() { … }’
‘def myFunction() { … }’
11.Which function allows you to iterate over a range of numbers in Kotlin?
‘forEach’
‘range’
‘until’
‘step’
12.What does the ‘!!’ operator do in Kotlin?
Forces a nullable type to be non-null and throws an exception if it is null
Converts a non-null type to nullable
Checks for nullability and returns false if null
Safely casts a nullable type
13.What is the default visibility modifier for class members in Kotlin?
‘public’
‘protected’
‘private’
‘internal’
14.How can you define an extension function in Kotlin?
‘fun String.extensionFunction() { … }’
‘fun extensionFunction(String) { … }’
‘fun String.extFunction() { … }’
‘fun extensionFunction(String) { … }’
15.Which Kotlin keyword is used to represent a generic type?
‘type’
‘generic’
‘T’
‘Any’
16.What is the result of the following expression: ‘5?.let { it * 2 }’?
’10’
‘null’
‘5’
‘2’
17.What does the ‘sealed’ keyword denote in Kotlin?
An enum-like class with a limited set of subclasses
A class that cannot be inherited
A final class
A class with private constructors
18.Which of the following is a valid way to create an instance of a Kotlin data class?
‘val obj = MyDataClass(1, “name”)’
‘val obj = new MyDataClass(1, “name”)’
‘val obj = MyDataClass.create(1, “name”)’
‘val obj = MyDataClass.createInstance(1, “name”)’
19.How do you declare a variable in Kotlin that can hold both ‘String’ and ‘Int’ types?
‘var value: Any’
‘var value: String | Int’
‘var value: (String, Int)’
‘var value: String & Int’
20.What does the ‘when’ keyword do in Kotlin?
It is used for branching similar to ‘switch’ in other languages
It is used to handle exceptions
It initializes variables
It creates anonymous functions
Which keyword is used to define a class in Kotlin?
Answer: 'class'
Which of the following is used to declare a read-only variable in Kotlin?
Answer: 'val'
How do you declare a nullable type in Kotlin?
Answer: 'String?'
What is the primary constructor syntax in Kotlin?
Answer: 'class MyClass(val x: Int)'
How do you define a function that does not return any value in Kotlin?
Answer: 'fun myFunction(): Unit { ... }'
Which keyword is used to extend a class or interface in Kotlin?
Answer: ':'
What is the purpose of the ‘data’ keyword in Kotlin?
Answer: To define data classes that automatically generate equals()
, hashCode()
, and toString()
methods
How do you handle exceptions in Kotlin?
Answer: 'try-catch-finally'
Which keyword is used to declare an interface in Kotlin?
Answer: 'interface'
How do you declare a top-level function in Kotlin?
Answer: 'fun myFunction() { ... }'
Which function allows you to iterate over a range of numbers in Kotlin?
Answer: 'forEach'
What does the ‘!!’ operator do in Kotlin?
Answer: Forces a nullable type to be non-null and throws an exception if it is null
What is the default visibility modifier for class members in Kotlin?
Answer: 'public'
How can you define an extension function in Kotlin?
Answer: 'fun String.extensionFunction() { ... }'
Which Kotlin keyword is used to represent a generic type?
Answer: 'T'
What is the result of the following expression: 5?.let { it * 2 }
?
Answer: '10'
What does the ‘sealed’ keyword denote in Kotlin?
Answer: An enum-like class with a limited set of subclasses
Which of the following is a valid way to create an instance of a Kotlin data class?
Answer: 'val obj = MyDataClass(1, "name")'
How do you declare a variable in Kotlin that can hold both String
and Int
types?
Answer: 'var value: Any'
What does the ‘when’ keyword do in Kotlin?
Answer: It is used for branching similar to switch
in other languages