191.
192.
Line 3 is invalid. The value
two is not
valid since single quotes
cannot be used for a String, they can
only be used for a character
constant. Strings need to be enclosed in double quotes.
Line 4 is invalid. The byte variable
b cannot
be assigned the
value 256 since it is out of the range of a byte.
What is the use of transient keyword?
Answer:
The transient keyword can be specified on an instance variable.
Specifying transient for an instance variable indicates that its
state should not be saved when the object is serialized. Consider
the following code snippet:
class Electronics implements Serializable {
transient private int price; //Line 1
private int quantity; //Line 2
}
When an instance of the Electronics class
is serialized, the
price field will not be serialized, only
the quantity field will be
serialized.
What is Garbage Collection in Java?
Answer:
Garbage collection is the process of freeing memory allocated to
objects that are no longer used.
During runtime, when an object
is created, the JVM allocates some memory to hold the object.
The JVM periodically checks for objects that are in use and de–
allocates the memory for those
objects which are not in use
anymore. Garbage collection is this process of removing objects
193.
194.
195.
that are no longer in use. So, the
programmer does not have to
bother about manual de–allocation of memory.
Do'stlaringiz bilan baham: