Characteristics of java constructor

  • An interface cannot have the constructor.
  • Constructors cannot be private.
  • A constructor cannot be abstract, static, final, native, strictfp, or synchronized
  • A constructor can be overloaded.
  • Constructors cannot return a value.
  • Constructors do not have a return type; not even void.
  • An abstract class can have the constructor.
  • Constructors name must be similar to that of the class name inside which it resides.
  • Constructors are automatically called when an object is created.

Instance variables and methods of a class are known as members of a class. Constructors are not members. For this reason, constructors cannot be inherited; but can be accessed by a subclass. Java constructors do not get inherited; only their members (variables and methods) get inherited. So declaring a constructor as final is useless and has no meaning as constructors cannot be overridden. Again, Java constructors should not be synchronized as it locks the object when created and hence, as long as the object is not created any other object can be instantiated.

Posted on by