Sample questions
Question 1Easy
- A layer over SQLite
- A cloud database service
- A network library
- A UI toolkit
Answer: A. A layer over SQLite
Explanation
Room adds compile-time SQL checks and maps rows to Kotlin objects.
Step-by-step solution
- Room is part of Android Jetpack.
- It wraps SQLite with annotations and generated code.
- It checks queries at compile time.
Why the other options are wrong
- B. Room is a local database.
- C. Networking uses libraries like Retrofit.
- D. UI toolkits are Compose or Views.
Question 2Easy
Which annotation marks a Room interface that declares database queries?
- @Query only
- @Entity
- @Dao
- @Database
Answer: C. @Dao
Explanation
DAOs (Data Access Objects) hold @Query, @Insert, @Update and @Delete methods.
Step-by-step solution
- A DAO is an interface (or abstract class) with query methods.
- It is annotated with @Dao.
- Its methods use @Query, @Insert, @Update and @Delete.
Why the other options are wrong
- A. @Query marks a method, not the interface.
- B. @Entity marks a table class.
- D. @Database marks the database class.
Tip: Room trio: @Entity, @Dao, @Database.
Question 3Easy
The Room database class must extend:
- RoomDatabase
- SQLiteOpenHelper
- Application
- ViewModel
Answer: A. RoomDatabase
Explanation
It is abstract and annotated with @Database(entities = [...], version = n).
Step-by-step solution
- The database class is abstract and annotated @Database.
- It extends RoomDatabase.
- It exposes abstract functions that return each DAO.
Why the other options are wrong
- B. SQLiteOpenHelper is the older, manual approach that Room hides.
- C. Application is the app-wide class, not a database.
- D. ViewModel holds UI state, not the database.
Tip: @Database abstract class AppDb: RoomDatabase().
Question 4Easy
Which annotation marks a Kotlin class as a Room table?
- @Table
- @Model
- @Entity
- @Dao
Answer: C. @Entity
Explanation
Each @Entity class maps to a table.
Step-by-step solution
- A Room table is defined by a data class.
- The class is annotated @Entity.
- Each property becomes a column; one is marked @PrimaryKey.
Why the other options are wrong
- A. Room has no @Table annotation.
- B. @Model is not a Room annotation.
- D. @Dao is for the query interface.
Tip: Entity = table.
Question 5Medium
What does @PrimaryKey(autoGenerate = true) val id: Long = 0 do?
- SQLite assigns the ID
- Makes the ID a String
- Requires you to set unique IDs
- Creates a foreign key
Answer: A. SQLite assigns the ID
Explanation
A value of 0 is treated as unset, so a new ID is generated.
Step-by-step solution
- autoGenerate = true lets SQLite assign the next ID.
- The default 0 tells Room the ID is unset.
- After insert, the new row gets a unique ID.
Why the other options are wrong
- B. The type stays Long.
- C. You do not need to supply IDs.
- D. Foreign keys are declared separately.
Question 6Medium
A DAO method returns Flow<List<Note>>. What happens when a note is inserted?
- Nothing until the app restarts
- The Flow completes
- An exception is thrown
- It emits the new list
Answer: D. It emits the new list
Explanation
Room observes table changes and re-runs the query for active collectors.
Step-by-step solution
- Room tracks which tables a query reads.
- When a write changes those tables, Room reruns the query.
- The Flow emits the updated list.
Why the other options are wrong
- A. Updates arrive immediately.
- B. Room Flows do not complete on their own.
- C. Inserts are normal.
Question 7Medium
Marking a DAO method as suspend fun insert(note: Note) means:
- It is called from coroutines
- It blocks the UI thread
- It runs at compile time
- It can only be called from Java
Answer: A. It is called from coroutines
Explanation
Room runs suspend DAO methods on a background executor.
Step-by-step solution
- suspend functions can only be called from a coroutine or another suspend function.
- Room runs suspend DAO methods on a background executor.
- So the call does not block the UI thread.
Why the other options are wrong
- B. suspend functions do not block the thread that calls them.
- C. They run at runtime, not at compile time.
- D. suspend functions are awkward to call from Java.
Tip: One-shot DAO call = suspend; live updates = Flow.
Question 8Medium
Room needs TypeConverters to store which kind of field directly?
- An Instant
- String
- Int
- ByteArray (BLOB)
Answer: A. An Instant
Explanation
Converters map unsupported types to supported column types like Long or String.
Step-by-step solution
- SQLite stores only basic types: integers, reals, text and blobs.
- Room maps String, Int and ByteArray directly.
- An Instant (date-time) needs a TypeConverter, e.g. to a Long timestamp.
Why the other options are wrong
- B. String maps to TEXT.
- C. Int maps to INTEGER.
- D. ByteArray maps to BLOB.
Question 9Medium
@Insert(onConflict = OnConflictStrategy.REPLACE) means:
- The table is cleared first
- Duplicates are always ignored
- Clashing rows are replaced
- An exception is thrown on conflict
Answer: C. Clashing rows are replaced
Explanation
REPLACE deletes the conflicting row and inserts the new one.
Step-by-step solution
- A conflict happens when the primary key (or unique index) already exists.
- REPLACE deletes the old row and inserts the new one.
- The result is an upsert.
Why the other options are wrong
- A. Only the clashing row is replaced.
- B. IGNORE skips duplicates.
- D. ABORT, the default, throws.
Question 10Hard
You add a column to an entity and bump the database version from 1 to 2 without a Migration. On an existing install, what happens (with no destructive fallback)?
- Old data is kept and the column ignored
- It crashes on startup
- Room downgrades to version 1
- Room adds the column automatically
Answer: B. It crashes on startup
Explanation
Provide a Migration(1, 2), an auto-migration, or explicitly allow destructive migration.
Step-by-step solution
- The schema changed and the version went up.
- Room needs a migration path from 1 to 2.
- With none and no destructive fallback, it throws IllegalStateException when the database opens, crashing the app.
Why the other options are wrong
- A. Room refuses to open a database with a mismatched schema.
- C. Room never downgrades automatically.
- D. Room does not alter tables without a migration.
Practise all 13 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →