title: What is the correct encapsulation in java object types
body: <p>What is the correct encapsulation from below 2 classes in java?.I saw both these approches in many codes(mostly 1st approche). But seems like 2nd approach is the correct one.</p>
  
  <pre><code>import java.util.Date;
  
  public class SomeClass
  {
      private Date date;
  
      public Date getDate()
      {
          return date;
      }
  
      public void setDate(Date date)
      {
          this.date = date;
      }   
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>import java.util.Date;
  
  public class SomeClass
  {
      private Date date;
  
      public Date getDate()
      {
          return (Date) date.clone();
      }
  
      public void setDate(Date date)
      {
          this.date = (Date) date.clone();
      }
  
  }
  </code></pre>