title: Private members variables in Data Class in Kotlin
body: <p>I am new to kotlin and when I was reading about the data classes in kotlin and I found these code.Its basically a comparision between the java model class and kotlin data class and it was wriiten over there that both the code do the same task.</p>
  
  <p>Code 1</p>
  
  <pre><code>public class VideoGame {
  
  private String name;
  private String publisher;
  private int reviewScore;
  
  public VideoGame(String name, String publisher, int reviewScore) {
      this.name = name;
      this.publisher = publisher;
      this.reviewScore = reviewScore;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getPublisher() {
      return publisher;
  }
  
  public void setPublisher(String publisher) {
      this.publisher = publisher;
  }
  
  public int getReviewScore() {
      return reviewScore;
  }
  
  public void setReviewScore(int reviewScore) {
      this.reviewScore = reviewScore;
  }}
  </code></pre>
  
  <p>Code 2</p>
  
  <pre><code>data class VideoGame(val name: String, val publisher: String, var reviewScore: Int)
  </code></pre>
  
  <p>My question is that <strong>In the data class all the variable are public and not private and  any anyone can directly access the variable with the help of a  object of this class but in the java code all the variable are private that's why we have to write the getter and setter for these member variable if it was public there is no need of getter and setter.So how these codes are same?</strong></p>