Java Reference
In-Depth Information
QAre
private
variables and objects saved when they are part of an object that's
being serialized?
A
They are saved. As you might recall from today's discussion, no constructor meth-
ods are called when an object is loaded into a program using serialization. Because
of this, all variables and objects not declared
transient
are saved to prevent the
object from losing something that might be necessary to its function.
Saving
private
variables and objects might present a security risk in some cases,
especially when the variable is being used to store a password or some other sensi-
tive data. Using
transient
prevents a variable or object from being serialized.
Review today's material by taking this three-question quiz.
Questions
1.
What is returned when you call
getName()
on a
Class
object that represents a
String[]
array?
a.
java.lang.String
b.
[Ljava.lang.String
c.
[java.lang.String
2.
What is persistence?
a.
The capability of an object to exist after the program that created it has
stopped running
b.
The ability of a class to support multiple threads
c.
An error-handling technique
3.
What
Class
method is used to create a new
Class
object using a string containing
the name of a class?
a.
newInstance()
b.
forName()
c.
getName()