Java Constructor vs method

Functionally difference between constructors and methods is that constructors create and initialize objects that don't exist yet, while methods perform operations on objects that already exist.

Constructors can't be called directly. They are invoked implicitly when the new keyword creates an object.
Methods can be called directly on an object that has already been created with new.

Constructors must be named with the same name as the class name.

Constructors cannot  return anything, even void .

Methods must be declared to return something ( or void).

Constructor compiler provide default constructor where as method compiler does't provide.

Constructor cannot be final since it cant be inherited.

Constructor cannot be abstract since it is used to create and initialize object.

Constructor cannot be static since it is used to create instance of object.

Only public, protected & private modifiers are permitted.

Comments

Popular posts from this blog

Converting Java Map to String

Difference between volatile and synchronized

Invoking EJB deployed on a remote machine