• +91 9723535972
  • info@interviewmaterial.com

Kotlin Interview Questions and Answers

Question - What is a data class in Kotlin?

Answer -

In Kotlin, a data class is a class whose main purpose is to hold data. It is marked as "data".

Syntax:

data class User(val name: String, val age: Int)   
The data classes must have to fulfill the following requirements to ensure consistency and meaningful behavior of the generated code:

  • The primary constructor must have at least one parameter
  • , and all primary constructor parameters need to be marked as val or var.
  • Data classes cannot be abstract, open, sealed, or inner.

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners