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

senior

Why is there no static keyword in Kotlin?

middle

When would you use Elvis operator in Kotlin?

middle

What is the difference between open and public in Kotlin?

Bình luận

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

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