Use Sealed Classes when you have a restricted class hierarchy where a value can have one of a limited set of types.
when: The compiler forces you to handle all subclasses in a when expression, ensuring type safety.sealed class UiState {
object Loading : UiState()
data class Success(val data: String) : UiState()
data class Error(val message: String) : UiState()
}
Mark this when you can explain the answer in your own words.
Help fellow developers prepare for interviews
Sharing helps the Android community grow ๐