206. What is Garbage Collection and how to call it explicitly?
Ans. When an object is no longer referred to by any variable, java automatically
reclaims memory used by that object. This is known as garbage collection. System.
gc() method may be used to call it explicitly.
207. What is finalize() method?
Ans. finalize () method is used just before an object is destroyed and can be
called just prior to garbage collection.
208. What are Transient and Volatile Modifiers?
Ans. Transient: The transient modifier applies to variables only and it is not
stored as part of its object’s Persistent state. Transient variables are not
serialized. Volatile: Volatile modifier applies to variables only and it tells the
compiler that the variable modified by volatile can be changed unexpectedly by
other parts of the program.
209. What is method overloading and method overriding?
Ans. Method overloading: When a method in a class having the same method name with
different arguments is said to be method overloading. Method overriding : When a
method in a class having the same method name with same arguments is said to be
method overriding.
210. What is difference between overloading and overriding?
Ans. a) In overloading, there is a relationship between methods available in the
same class whereas in overriding, there is relationship between a superclass method
and subclass method. b) Overloading does not block inheritance from the superclass
whereas overriding blocks inheritance from the superclass. c) In overloading,
separate methods share the same name whereas in overriding, subclass method
replaces the superclass. d) Overloading must have different method signatures
whereas overriding must have same signature.
Saturday, May 10, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment