Câu hỏi phỏng vấn Kotlin
Câu hỏi

What is a difference between a class and object in Kotlin?

Câu trả lời

Here is an explanation of the difference between a class and an object in Kotlin:

Classes

  • A class is a blueprint or template for creating objects
  • It defines the properties (data) and functions (behavior) that objects of that class will have
  • Classes are defined using the class keyword followed by the class name
  • You can create multiple objects from a single class
  • Classes are not instantiated until an object is created from them

Objects

  • An object is a specific instance of a class
  • It contains the actual data and can perform the behaviors defined in the class
  • Objects are created from classes using the new keyword or a constructor
  • Each object has its own copy of the properties defined in the class
  • Objects can access and modify their own properties and call their own functions

The key differences are:

  • A class is a template, while an object is a...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

Explain advantages of when vs switch in Kotlin

expert

How Kotlin coroutines are better than RxKotlin/RxJava?

senior

Explain the difference between Inline classes vs type aliases

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào