0% found this document useful (0 votes)
81 views8 pages

Android Kotline Objective Questions and Answers

Uploaded by

lakshmana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views8 pages

Android Kotline Objective Questions and Answers

Uploaded by

lakshmana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Android Kotline Objective questions and answers

1. What is the primary purpose of the val keyword in Kotlin?


 A) To declare a mutable variable
 B) To declare a read-only variable
 C) To declare a function
 D) To define a class
 Answer: B) To declare a read-only variable
2. Which of the following is a feature of Kotlin?
 A) Null safety
 B) Automatic memory management
 C) No interoperability with Java
 D) Verbose syntax
 Answer: A) Null safety
3. What does the data keyword indicate in a Kotlin class?
 A) The class can be instantiated
 B) The class is used for holding data
 C) The class has no constructor
 D) The class is abstract
 Answer: B) The class is used for holding data
4. Which of the following is NOT a valid way to declare a function in Kotlin?
 A) fun myFunction() {}
 B) function myFunction() {}
 C) fun myFunction(param: Int): String {}
 D) fun myFunction(param: Int) = "Result"
 Answer: B) function myFunction() {}
5. What is the purpose of the lateinit modifier in Kotlin?
 A) To declare a variable that can be null
 B) To delay the initialization of a variable
 C) To create an immutable variable
 D) To define a static variable
 Answer: B) To delay the initialization of a variable
6. Which of the following is used to define a companion object in Kotlin?
 A) object
 B) static
 C) companion
 D) class
 Answer: C) companion
7. How do you declare a nullable variable in Kotlin?
 A) var name: String = null
 B) var name: String?
 C) var name: String!
 D) var name: String? = null
 Answer: B) var name: String?
8. What is the correct way to launch a coroutine in Kotlin?
 A) CoroutineScope.start { }
 B) CoroutineScope.run { }
 C) GlobalScope.launch { }
 D) CoroutineScope.execute { }
 Answer: C) GlobalScope.launch { }
9. Which of the following is true about extension functions in Kotlin?
 A) They can modify the original class.
 B) They can only be defined in the same file as the class.
 C) They can be called as if they are member functions.
 D) They cannot be used with built-in types.
 Answer: C) They can be called as if they are member functions.
10. What does the apply function do in Kotlin?
 A) It applies a function to a variable and returns a new variable.
 B) It allows you to configure an object and returns the object itself.
 C) It executes a block of code and returns the last expression.
 D) It is used to create a new thread.
 Answer: B) It allows you to configure an object and returns the object itself.
11. Which of the following keywords is used to create a
singleton in Kotlin?
 A) object
 B) singleton
 C) static
 D) companion
 Answer: A) object
12. What is the purpose of the when expression in Kotlin?
 A) To define a loop
 B) To handle exceptions
 C) To perform conditional branching
 D) To declare a variable
 Answer: C) To perform conditional branching
13. Which of the following is the correct way to define a lambda
expression in Kotlin?
 A) val sum = { a: Int, b: Int -> a + b }
 B) val sum: (Int, Int) -> Int = { a, b -> a + b }
 C) Both A and B
 D) None of the above
 Answer: C) Both A and B
14. In Kotlin, how can you create a list that cannot be modified?
 A) val list = mutableListOf()
 B) val list = listOf()
 C) val list = ArrayList()
 D) val list = LinkedList()
 Answer: B) val list = listOf()
15. What is the correct way to declare an interface in Kotlin?
 A) interface MyInterface {}
 B) class MyInterface {}
 C) abstract class MyInterface {}
 D) fun MyInterface {}
 Answer: A) interface MyInterface {}
16. Which of the following is used to handle asynchronous
programming in Kotlin?
 A) Threads
 B) Callbacks
 C) Coroutines
 D) Executors
 Answer: C) Coroutines
17. What is the output of the following code?
kotlin
Copy
val x = 5
val y = 10
val max = if (x > y) x else y
 A) 5
 B) 10
 C) 15
 D) Error
 Answer: B) 10
18. Which of the following annotations is used to indicate that a
function is a coroutine in Kotlin?
 A) @Coroutine
 B) @Suspend
 C) @Suspendable
 D) @SuspendFunction
 Answer: B) @Suspend
19. How do you create a custom view in Android using Kotlin?
 A) By extending the View class
 B) By implementing the CustomView interface
 C) By using
the createView() method
 D) By extending the Activity class
 Answer: A) By extending the View class
20. What is the purpose of the withContext function in Kotlin
coroutines?
 A) To switch to a different coroutine context
 B) To create a new coroutine
 C) To cancel a coroutine
 D) To delay execution
 Answer: A) To switch to a different coroutine context
21. Which of the following is the correct syntax to create a
mutable list in Kotlin?
 A) val list = listOf()
 B) val list = mutableListOf()
 C) val list = ArrayList()
 D) val list = LinkedList()
 Answer: B) val list = mutableListOf()
22. What is the purpose of the sealed class in Kotlin?
 A) To allow inheritance from multiple classes
 B) To restrict class inheritance to a limited set of types
 C) To create a singleton instance
 D) To define an interface
 Answer: B) To restrict class inheritance to a limited set of types
23. Which of the following is NOT a valid visibility modifier in
Kotlin?
 A) public
 B) private
 C) protected
 D) internal
 Answer: D) internal
24. How can you define a function that can accept a variable
number of arguments in Kotlin?
 A) Using the vararg keyword
 B) Using the args keyword
 C) Using an array parameter
 D) Using a List parameter
 Answer: A) Using the vararg keyword
25. In Kotlin, how do you create a read-only property?
 A) Use var
 B) Use val
 C) Use const
 D) Use lateinit
 Answer: B) Use val
26. What is the default visibility of classes in Kotlin?
 A) public
 B) private
 C) protected
 D) internal
 Answer: A) public
27. Which of the following is a valid way to handle exceptions
in Kotlin?
 A) try-catch
 B) catch-try
 C) throw-catch
 D) exception-catch
 Answer: A) try-catch
28. How do you define a primary constructor in a Kotlin class?
 A) By using the constructor keyword
 B) By defining parameters in the class header
 C) By creating an init block
 D) By using the init keyword
 Answer: B) By defining parameters in the class header
29. What is the purpose of the apply function in Kotlin?
 A) To apply a function to a variable
 B) To create a new instance of a class
 C) To configure an object and return the object itself
 D) To execute a block of code and return the last expression
 Answer: C) To configure an object and return the object itself
30. Which of the following is NOT a built-in collection type in
Kotlin?
 A) List
 B) Set
 C) Map
 D) ArrayList
 Answer: D) ArrayList
31. What is the purpose of the let function in Kotlin?
 A) To define a variable
 B) To execute a block of code on a nullable object
 C) To create a coroutine
 D) To declare a data class
 Answer: B) To execute a block of code on a nullable object
32. Which of the following is the correct way to create an
extension property in Kotlin?
 A) val String.length: Int
 B) var String.length: Int
 C) val String.extraLength: Int get() = this.length + 10
 D) fun String.length(): Int
 Answer: C) val String.extraLength: Int get() = this.length + 10
33. What is the output of the following code snippet?
kotlin
Copy
val numbers = listOf(1, 2, 3)
val result = numbers.map { it * 2 }
 A) [1, 2, 3]
 B) [2, 4, 6]
 C) [3, 6, 9]
 D) Error
 Answer: B) [2, 4, 6]
34. Which of the following is a valid way to create a coroutine
scope in Kotlin?
 A) CoroutineScope()
 B) GlobalScope()
 C) CoroutineScope.launch { }
 D) CoroutineScope.async { }
 Answer: A) CoroutineScope()
35. What is the primary use of the @JvmStatic annotation in
Kotlin?
 A) To indicate a method can be called from Java as a static method
 B) To indicate a variable is static
 C) To define a companion object
 D) To create an interface
 Answer: A) To indicate a method can be called from Java as a
static method
36. Which of the following is true about suspend functions in
Kotlin?
 A) They can be called from any thread
 B) They can only be called from other suspend functions or
coroutines
 C) They must always return a value
 D) They cannot have parameters
 Answer: B) They can only be called from other suspend functions or
coroutines
37. What is the purpose of the runBlocking function in Kotlin?
 A) To run a coroutine in a new thread
 B) To block the current thread until the coroutine completes
 C) To launch a coroutine without blocking
 D) To define a coroutine scope
 Answer: B) To block the current thread until the coroutine
completes
38. Which of the following correctly describes a BroadcastReceiver
in Android?
 A) It is used to send data between activities
 B) It listens for system-wide broadcast announcements
 C) It manages UI components
 D) It handles user interactions
 Answer: B) It listens for system-wide broadcast announcements
39. What is the function of the onCreate() method in an Android
Activity?
 A) To handle user input
 B) To initialize the activity and set up the user interface
 C) To manage background tasks
 D) To destroy the activity
 Answer: B) To initialize the activity and set up the user interface
40. How do you declare a fragment in Kotlin?
 A) By extending the Fragment class
 B) By implementing the Fragment interface
 C) By using the fragment keyword
 D) By creating a new Activity
 Answer: A) By extending the Fragment class

Here are some Android Studio multiple-choice questions and answers to help you prepare:
Basic Concepts:
1. What is the primary language used for Android app development?
o a) Java
o b) Kotlin
o c) C++
o d) Python
Answer: b)
2. What is the role of the AndroidManifest.xml file?
o a) Defines the app's user interface layout
o b) Contains the app's source code
o c) Declares the app's components and permissions
o d) Stores the app's resources
Answer: c)
3. What is the purpose of the Android SDK?
o a) To develop iOS apps
o b) To provide tools and libraries for Android app development
o c) To compile and run Java programs
o d) To create web applications
Answer: b)
4. What is the core component of an Android app that provides a visual interface?
o a) Service
o b) Activity
o c) Broadcast Receiver
o d) Content Provider
Answer: b)
5. What is the purpose of the Gradle build system in Android Studio?
o a) To manage app dependencies and build process
o b) To debug app code
o c) To design app layouts
o d) To test app performance
Answer: a)
Intermediate Concepts:
6. What is the difference between a Fragment and an Activity?
o a) Fragments are reusable UI components, while Activities are complete screens.
o b) Fragments are used for background tasks, while Activities are for user interaction.
o c) Fragments are for data storage, while Activities are for network operations.
o d) There is no significant difference between them.
Answer: a)
7. What is the role of the Intent class in Android?
o a) To define user interface layouts
o b) To manage background services
o c) To initiate actions and start activities or services
o d) To store and retrieve app data
Answer: c)
8. What is the purpose of the Android Virtual Device (AVD)?
o a) To emulate different Android devices and versions
o b) To debug app code
o c) To design app layouts
o d) To manage app permissions
Answer: a)
9. What is the difference between a static resource and a dynamic resource in Android?
o a) Static resources are changed at runtime, while dynamic resources are fixed.
o b) Static resources are defined in XML files, while dynamic resources are generated at
runtime.
o c) Static resources are loaded from the network, while dynamic resources are stored
locally.
o d) There is no significant difference between them.
Answer: b)
10. What is the role of the Resource Qualifier in Android?
 a) To define the app's permissions
 b) To specify different resource values for different device configurations
 c) To manage background services
 d) To initiate actions and start activities or services
Answer: b)

You might also like