(^358) | Inheritance, Polymorphism, and Scope
Here is the screen output from the application ObjectFileRead:
You should note two additional points of syntax. The first is how the object files are
instantiated:
inObject =
new ObjectInputStream(new FileInputStream("outObject.dat"));
outObject =
new ObjectOutputStream(new FileOutputStream("outObject.dat"));
This follows the pattern of BufferedReader and PrintWriter: FileInputStream and
FileOutputStreamobjects are instantiated as arguments to the ObjectInputStreamand
ObjectOutputStreamconstructors.
The second thing to notice is that the input object has to be type cast back into aName
object. The object that is input is just a sequence of bits. We must indicate how to break up
this sequence of bits into the proper fields by using the appropriate class name as a type cast.
person = (Name)inObject.readObject();
Now that we have seen the mechanics of implementing a derived class and discussed
the method for designing a class interface, let’s bring all the pieces together in a Case Study
that illustrates the process.
やまだぃちぅ
(やまだぃちぅ)
#1