Q1 . What
is the difference between a constructor and a method?
A. A
constructor is a member function of a class that is used to create objects of
that class. It has the same name as the class itself, has no return type, and
is invoked using the new operator.
A
method is an ordinary member function of a class. It has its own name, a return
type (which may be void), and is invoked using the dot operator.
Q2. What is the purpose of garbage collection in Java, and when is it used?
A.
The purpose of garbage collection is to identify and discard objects that
are no longer needed by a program so that their resources can be reclaimed and
reused. A Java object is subject to garbage collection when it becomes
unreachable to the program in which it is used.
Q3. Describe synchronization in respect to multithreading.
A.
With respect to multithreading, synchronization is the capability to control
the access of multiple threads to shared resources. Without synchonization, it
is possible for one thread to modify a shared variable while another thread is
in the process of using or updating same shared variable. This usually leads to
significant errors.
Q4. What is an abstract class?
A.
Abstract class must be extended/subclassed (to be useful). It serves as a
template. A class that is abstract may not be instantiated (ie. you may not
call its constructor), abstract class may contain static data.
Any
class with an abstract method is automatically abstract itself, and must be
declared as such. A class may be declared abstract even if it has no abstract
methods. This prevents it from being instantiated.
| Next |