title: Passing only value for private members
body: <p>I am creating a class with one array as its private member and getter,setter method for that. I want set a value to that array using an array in main function. When I manipulate the array in main function, it should not affect the array present in that class.</p>
  
  <p>I tried this code, but here the array is manipulated</p>
  
  <pre><code>class ClassB {
  
      private int[] a;
  
      ClassB() { }
  
      ClassB(int[] a) {
          this.a=a;
      }
  
      int[] geta() {
          return this.a;
      }
  
      void seta(int a[]) {
          this.a = a;
      }
  }
  
  public class ClassA{
  
      public static void main(String[] args) {
  
          Scanner sc = new Scanner(System.in);
          System.out.println("Enter size : ");
          int n = sc.nextInt();
          int[] d = new int[n];
          System.out.println("Enter array elements : ");
          for (int i=0 ; i&lt;n ; i++) {
              d[i] = sc.nextInt();
          }
          final ClassB cb2 = new ClassB(d);
          d[3] = 15;
          System.out.println("After changing array d : \n Values of array d :");
          for (int i=0 ; i&lt;n ; i++) {
              System.out.println(d[i]);
          }
          System.out.println("Values of array a of cb2 :");
          int[] b = cb2.geta();
          for (int i=0 ; i&lt;n ; i++) {
              System.out.println(b[i]);
          }
      }
  }
  </code></pre>
  
  <p>I expect :</p>
  
  <pre><code>Enter size :
  
  5
  
  Enter array elements :
  1
  2
  3
  4
  5
  After changing array d :
  
   Values of array d :
  
  1
  2
  3
  15
  5
  
  Values of array a of cb2 :
  1
  2
  3
  4
  5
  </code></pre>
  
  <p>But the actual output was :</p>
  
  <pre><code>Enter size :
  
  5
  
  Enter array elements :
  
  1
  2
  3
  4
  5
  
  After changing array d :
  
   Values of array d :
  
  1
  2
  3
  15
  5
  
  Values of array a of cb2 :
  
  1
  2
  3
  15
  5
  </code></pre>