Witscale Test Center

3.8 Constructors and modifiers > 3.8.5 Declaration facts for constructors


3.8.5 Declaration facts for constructors

Constructors are special methods of the class due to their role in object creation process. Syntactically too they are different. Following are the facts that summarize how they are different from the other methods of a class:

         The constructor declaration is very similar to a method declaration, but its name must be exactly same as the class’s name.

         The constructor declaration does not have return type (not even void).

         None of the non-access modifiers is applicable to constructor declaration. The constructor is not inherited [l7] from the superclass. Therefore, the modifiers such as final or abstract do not make sense to it. The modifier static is also not applicable to a constructor. Constructor is invoked to create an object and is associated with an object therefore it cannot be static.