Notes - 190916 - Copying Objects
Notes - 190916 - Copying Objects
Test Topics
ArrayLists (7.13)
Arrays (chapter 7)
2D arrays (7.12)
toString method (chapter 8.4)
Classes & objects (including constructors) (chapter 6 and 8)
equals method (chapter 8.5)
this keyword (chapter 8.9)
Passing by reference vs passing by value (8.2)
-----------------------------------
Copy method/copy constructor (8.3, 8.6)
Aggregation (8.4)
Static class members* (8.1)
69 //copy method
70 //creates a NEW INSTANCE of a Person object, copies the attribute values of the calling object and return
71 //the new object
72 //modifier returnType methodName (parameters)
73 public Person copy(){
74 //create new instance of a Person object
75 Person other = new Person(this.first, this.last, this.midInit);
76
77 //return the new object
78 return other;
79
80 //or you can do it in one line like this!
81 //create an anonymous object
82 //return new Person(this.first, this.last, this.midInit);
83 }