if you please explain more about array of objects and why we Do use new operator in accessor methods?
accessor methods are only for returning values, but on this example they create object at line 25 ,instead of returning elements of array a, directly?
public class ToyExample 6 { 7 private Date[] a; 8 public ToyExample(int arraySize) 9 { 10 a = new Date[arraySize]; 11 for (int i = 0; i < arraySize; i++) 12 a[i] = new Date(); 13 } 14 public ToyExample(ToyExample object) 15 { 16 int lengthOfArrays = object.a.length; 17 this.a = new Date[lengthOfArrays]; 18 for (int i = 0; i < lengthOfArrays; i++) 19 this.a[i] = new Date(object.a[i]); 20 } 21 public Date[] getDateArray() 22 { 23 Date[] temp = new Date[a.length]; 24 for (int i = 0; i < a.length; i++) 25 temp[i] = new Date(a[i]); 26 return temp; 27 }
I'm sorry the title is long.