




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The Kotlin and Android From Scratch Ultimate Exam is a complete evaluation of programming skills for aspiring Android developers. It covers Kotlin fundamentals, object-oriented programming, Android SDK components, UI/UX design, activity lifecycle, data storage, APIs, and debugging techniques. The exam includes practical coding scenarios and problem-solving exercises that simulate real-world app development challenges. Ideal for beginners and intermediate learners, this exam helps validate proficiency in building modern Android applications using Kotlin.
Typology: Exams
1 / 103
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which keyword is used to declare a read‑only variable in Kotlin? A) var B) val C) let D) const Answer: B Explanation: val creates an immutable reference; its value cannot be reassigned after initialization, unlike var which is mutable. Question 2. In Kotlin, what is the result of the expression 5 / 2 when both operands are of type Int? A) 2. B) 2 C) 3 D) Compilation error Answer: B Explanation: Integer division truncates the fractional part, so 5 / 2 yields 2. Question 3. How can you embed the value of a variable name inside a string literal? A) "Hello $name" B) "Hello ${name}" C) Both A and B
D) Neither A nor B Answer: C Explanation: Kotlin supports string templates using $variable or ${expression} syntax. Question 4. Which of the following is a valid raw string in Kotlin? A) """Hello\nWorld""" B) "Hello\nWorld" C) '''Hello''' D) Hello Answer: A Explanation: Triple‑quoted strings preserve line breaks and escape characters, making them raw strings. Question 5. Which statement about the when expression is FALSE? A) It can be used as a statement without a return value. B) It must always include an else branch. C) It can be used as an expression that returns a value. D) It can match multiple values in a single branch using commas. Answer: B Explanation: else is required only when the compiler cannot guarantee exhaustiveness; it is not mandatory in every when.
Answer: B Explanation: Kotlin uses the break@label syntax to exit a labeled loop. Question 9. Which of the following correctly defines a function with a default argument? A) fun greet(name: String = "Guest") { … } B) fun greet(name: String?) { … } C) fun greet(name: String?) = "Hello" D) fun greet(name: String) default "Guest" { … } Answer: A Explanation: Default arguments are provided using = after the parameter type. Question 10. What is the correct way to call a function sum(a: Int, b: Int = 5) providing only the first argument by name? A) sum(a = 3) B) sum(3) C) sum(b = 3) D) sum(3, ) Answer: A Explanation: Named arguments let you skip default parameters; sum(a = 3) uses the default for b. Question 11. Which type of Kotlin function can be passed as a parameter to another function?
A) Regular function only B) Lambda expression only C) Both regular functions and lambdas D) Neither Answer: C Explanation: Kotlin treats functions and lambdas as values of functional types, allowing them to be passed around. Question 12. In the declaration val transform: (Int) - > String = { it.toString() }, what does it represent? A) The function name B) The lambda’s single parameter C) The return type D) A placeholder for the result Answer: B Explanation: When a lambda has a single parameter, Kotlin lets you refer to it as it. Question 13. Which scope function returns the object it is called on after applying the block? A) let B) run C) also D) with
Question 16. In a primary constructor class Person(val name: String, var age: Int), what does val before name imply? A) name is a mutable property B) name is a read‑only property with a generated getter C) name is a local variable only visible inside the constructor D) name is a constant Answer: B Explanation: val creates an immutable property with a getter; var would create a mutable property with getter and setter. Question 17. How can you provide a custom getter for a property val isAdult: Boolean that returns age >= 18? A) val isAdult get() = age >= 18 B) val isAdult: Boolean = age >= 18 C) fun isAdult() = age >= 18 D) val isAdult: Boolean get() { return age >= 18 } Answer: A Explanation: Kotlin allows property accessors using get() syntax directly after the declaration. Question 18. Which of the following statements about data class is TRUE? A) All properties must be declared var B) The compiler automatically generates equals, hashCode, and copy C) data classes cannot implement interfaces
D) The primary constructor cannot have default values Answer: B Explanation: data class provides component functions, toString, equals, hashCode, and copy automatically. Question 19. What is the purpose of a sealed class? A) To allow multiple inheritance B) To restrict subclassing to the same file, enabling exhaustive when expressions C) To enforce immutability D) To hide the class from other modules Answer: B Explanation: sealed restricts subclassing to the same compilation unit, which helps the compiler know all possible subclasses. Question 20. Which visibility modifier makes a member visible only inside the same module? A) private B) protected C) internal D) public Answer: C Explanation: internal limits visibility to the same Gradle module (or Maven artifact).
D) val data: String = "" Answer: B Explanation: by lazy delegates the property to a thread‑safe lazy initializer, guaranteeing non‑null after first access. Question 24. In generic type parameters, what does out T signify? A) Contravariance – can accept subtypes of T as arguments B) Covariance – can produce subtypes of T as results C) Invariance – no variance allowed D) Mutable variance Answer: B Explanation: out makes the generic type covariant, allowing it to be used only in output positions. Question 25. Which syntax correctly defines an extension function isEven() for Int? A) fun Int.isEven(): Boolean = this % 2 == 0 B) fun isEven(Int): Boolean = this % 2 == 0 C) Int.fun isEven(): Boolean = this % 2 == 0 D) fun isEven(): Boolean = this % 2 == 0 Answer: A Explanation: Extension functions are declared as fun ReceiverType.functionName(...).
Question 26. What does the by keyword indicate when used as val delegate by lazy { … }? A) Property delegation B) Inheritance C) Interface implementation D) Inline function call Answer: A Explanation: by delegates the property’s getter/setter to the object returned by lazy. Question 27. Which block can catch a custom exception class MyError(message: String): Exception(message)? A) catch (e: Throwable) B) catch (e: MyError) C) catch (e: RuntimeException) D) All of the above Answer: D Explanation: MyError inherits from Exception, which inherits from Throwable; all three catch blocks would match, but the most specific (B) is preferred. Question 28. Which Android component is primarily responsible for handling long‑running background work without a UI? A) Activity B) Service C) BroadcastReceiver
Question 31. What is the difference between applicationContext and an Activity context? A) applicationContext is tied to the UI lifecycle, Activity context is not B) applicationContext lives as long as the app process, while Activity context is scoped to the Activity lifecycle C) There is no difference; they are interchangeable D) applicationContext can be used for inflating layouts, Activity context cannot Answer: B Explanation: applicationContext persists for the entire app process; an Activity context is destroyed when the Activity is destroyed. Question 32. Which Jetpack Compose annotation marks a function as composable? A) @Composable B) @UiThread C) @Preview D) @ComposableFunction Answer: A Explanation: @Composable tells the compiler that the function contributes to the UI hierarchy. Question 33. In Compose, which function is used to remember a mutable state that survives recompositions? A) remember { mutableStateOf(0) } B) mutableStateOf(0)
C) rememberMutableState(0) D) state { 0 } Answer: A Explanation: remember caches the MutableState across recompositions. Question 34. Which modifier makes a composable fill the maximum width of its parent? A) Modifier.width(IntrinsicSize.Max) B) Modifier.fillMaxWidth() C) Modifier.wrapContentWidth() D) Modifier.align(Alignment.Center) Answer: B Explanation: fillMaxWidth() expands the composable to match the parent’s width. Question 35. What is the purpose of Scaffold in Jetpack Compose? A) To provide a Material‑themed container with slots for top bar, bottom bar, FAB, etc. B) To create a grid layout C) To handle navigation between screens D) To manage coroutines Answer: A Explanation: Scaffold offers a standard layout structure for Material Design components.
C) ViewModel D) Repository Answer: C Explanation: ViewModel is lifecycle‑aware and retained across configuration changes like rotation. Question 39. Which Jetpack library provides type‑safe navigation between composable destinations? A) Navigation Component (androidx.navigation) B) Navigation Compose (androidx.navigation.compose) C) SafeArgs D) Hilt Navigation Answer: B Explanation: androidx.navigation.compose integrates the Navigation component with Compose and offers type‑safe arguments. Question 40. Which of the following statements about Data Binding vs. View Binding is correct? A) Data Binding can bind UI directly to LiveData/StateFlow, View Binding cannot. B) View Binding generates binding classes for every layout, Data Binding does not. C) Data Binding requires androidx.databinding plugin, View Binding does not. D) Both A and C are correct. Answer: D
Explanation: Data Binding supports expression language and two‑way binding; it needs the data binding plugin. View Binding only inflates views. Question 41. Which coroutine builder returns a Deferred that can be awaited for a result? A) launch B) async C) runBlocking D) withContext Answer: B Explanation: async starts a coroutine and returns a Deferred representing a future result. Question 42. Which dispatcher should be used for long‑running CPU‑intensive work? A) Dispatchers.Main B) Dispatchers.IO C) Dispatchers.Default D) Dispatchers.Unconfined Answer: C Explanation: Dispatchers.Default is optimized for CPU‑bound tasks. Question 43. What is the effect of using SupervisorJob() as the parent of a coroutine scope? A) Failure of one child cancels all siblings B) Failure of one child does not cancel its siblings
Explanation: @Query lets you write arbitrary SQL; SELECT * FROM users returns all rows. Question 46. How can you store a simple key‑value pair using the Preferences DataStore? A) dataStore.edit { it[KEY] = value } B) dataStore.putString(KEY, value) C) sharedPreferences.edit().putString(KEY, value).apply() D) dataStore.save(KEY, value) Answer: A Explanation: Preferences DataStore uses a MutablePreferences editor inside edit {}. Question 47. Which Retrofit annotation is used to send a POST request with a JSON body? A) @GET B) @POST C) @PUT D) @Body Answer: B (combined with @Body parameter) Explanation: @POST defines the HTTP method; the method parameter annotated with @Body supplies the JSON payload. Question 48. What is the purpose of an OkHttp interceptor? A) To intercept UI events B) To modify or observe outgoing requests and incoming responses
C) To schedule background work D) To provide dependency injection Answer: B Explanation: Interceptors can add headers, log traffic, or rewrite requests/responses. Question 49. Which pattern separates data sources (network, database) from the UI layer? A) MVC B) MVP C) Repository D) Singleton Answer: C Explanation: The Repository pattern abstracts data access, providing a clean API to the UI. Question 50. Which testing library is used for mocking Kotlin objects in unit tests? A) Mockito B) MockK C) EasyMock D) PowerMock Answer: B Explanation: MockK is designed for Kotlin, supporting coroutines, extension functions, and final classes.