(^354) | Inheritance, Polymorphism, and Scope
New SavingsAccount
Object
account = 4295110
name =
address =
phone =
balance = 8337.26
activation =
status = 1
Existing SavingsAccount
Object
account = 4295110
name =
address =
phone =
balance = 8337.26
activation =
status = 1
New Nested Objects
"Jane A. Smith"
"4731 East Oak St., Fossil, OR, 97364"
"541-555-9111"
month =
day = 17
year = 1993
"August"
Existing Nested Objects
"Jane A. Smith"
"4731 East Oak St., Fossil, OR, 97364"
"541-555-9111"
month =
day = 17
year = 1993
"August"
Figure 7.5 Deep Copying
7.8 Output and Input of Objects
The title of this section looks a bit strange. We usually talk about “input and output,” not “out-
put and input.” However, if we are talking about objects, they cannot be created outside the
application and read in. Rather, objects must be created in an application and then written
to a file. Once they are on a file, we can read the data values back in and re-create the object.
There are two ways to write and read objects. The first is to transform each data field of an
object into a string and then output the strings individually. The reverse transformation is
required to read in the strings representing data fields, convert them to the proper form, and
store them in the object’s fields. Transforming objects into strings and back again is a lot of