Thursday 31 March 2016

Difference Between Method and Constructor

Difference Between Method and Constructor

The main Difference Between Method and Constructor is;

Difference between method and constructor

Method can be any user-defined name and it should return some value. The constructor must be class name and It should not have any return type (even void) so it not return any value.
Method call by programmer manually but constructor call automatically when the object of the class is created.

Some Important Differences between Method and Constructor are;


  • Constructor are used to initialize the state of object,where as method is expose the behavior of object.
  • Constructor must not have return type where as method must have return type.
  • Constructor name same as the class name where as method may or may not the same class name.
  • Constructor invoke implicitly where as method invoke explicitly.
  • Constructor compiler provide default constructor where as method compiler does't provide.


No comments:

Post a Comment