Monday, August 4, 2008

Does Java have destructors

Does Java have destructors?

Garbage collector does the job working in the background
Java does not have destructors; but it has finalizers that does a similar job.
the syntax is
public void finalize(){
}
if an object has a finalizer, the method is invoked before the system garbage collects the object

What does the "abstract" keyword mean in front of a method? A class?

Abstract keyword declares either a method or a class.
If a method has a abstract keyword in front of it,it is called abstract method.Abstract method hs no body.It has only arguments and return type.Abstract methods act as placeholder methods that are implemented in the subclasses.
Abstract classes can't be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract

Are Java constructors inherited ? If not, why not?

You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's superclasses. One of the main reasons is because you probably don't want to overide the superclasses constructor, which would be possible if they were inherited. By giving the developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.