• +91 9723535972
  • info@interviewmaterial.com

Kotlin Interview Questions and Answers

Question - What is the difference between Java field and Kotlin property?

Answer -

This is an example of a Java field:

public String name = "Marcin";
Here is an example of a Kotlin property:

var name: String = "Marcin"
They both look very similar, but these are two different concepts. Direct Java equivalent of above Kotlin property is following:

private String name = "Marcin";
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
The default implementation of Kotlin property includes field and accessors (getter for val, and getter and setter for var). Thanks to that, we can always replace accessors default implementation with a custom one.

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners