CISC 124 Lecture Notes - Lecture 12: Object Copying

45 views1 pages

Document Summary

Obj1 points to object 1, so if you change obj2, obj 1 changes. Get elements and set them that way (see below code) Shallow copy: coppy the upper level, share the lower level (alias the secondary object time. Note: might want to check this online public appt copy() { Appt newappt = new appt() newappt. name = name; newappt. time = time; return newappt. Deep copy - need to copy all levels of objects. In the above method, you must copy the time as well. This includes strings, however, strings are immutable so you dont have to worry about it (will not be tested on this) Clonable - interface in java that has nothing in it. Object has a method called clone that is protected that returns a clone of the object. Since it it is protected you cannot just call it, your object must implement clonable.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents