Tuesday, March 20, 2007

Constructors in Java

Few points about constructors :

It has no return type.

It can use any access modifier, including private.

Its name must match the name of the class.

You could have both a method and a constructor with the same name in the same class.

Constructors are never inherited.

The default constructor is always a no-argument one.That is , it doesnot have arguments.

It can't be overridden.

It can be overloaded.

You cannot invoke an instance (in other words, nonstatic) method (or access an instance variable) until after the super constructor has run.

Key Rule: The first line in a constructor Must be a call to super() or a call to this().

No comments: