Mutable, Immutable, and Cloneable Objects
Mutable, Immutable, and Cloneable Objects
Cloneable Objects
Chapter 15
Chapter Contents
Mutable and Immutable Objects
• Companion Classes
• Using Inheritance to Form Companion
Classes
Cloneable Objects
A Sorted List of Clones
Cloning an Array
Cloning a Chain
2
Mutable and Immutable Objects
A mutable object belongs to a class that
has mutator or set methods for its data
fields
The client uses set methods to change
values of the object's data fields
Done
Doneby byexecuting
executing
chris.setLast
chris.setLast("Smith");
("Smith");
6
Companion Classes
15
Cloneable Objects
19
A Sorted List of Clones
23
Cloning a Chain
The ADT list class must implement the
interface Cloneable
24
Cloning a Chain